Ios 存储用于推送通知的令牌

Ios 存储用于推送通知的令牌,ios,node.js,swift,push-notification,apple-push-notifications,Ios,Node.js,Swift,Push Notification,Apple Push Notifications,我们的项目目前有一个NodeJS后端,我们希望为iOS实现推送通知。我们做了一些研究,发现我们必须将APN提供给我们的令牌存储在数据库中,以便向特定设备发送推送通知。是否有人可以确认这一点,或者是否有更好的方式发送通知 其次,我还发现,当设备进行软件更新时,这会改变它们的令牌,这是否意味着我们必须有能力更新数据库中的令牌,因为它会经常改变。这也相当重要。是否还有其他时间令牌可能发生更改 最后,节点中是否有用于发送推送通知的好库 提前谢谢 您必须将通知accessToken发送到服务器,这是要传递

我们的项目目前有一个NodeJS后端,我们希望为iOS实现推送通知。我们做了一些研究,发现我们必须将APN提供给我们的令牌存储在数据库中,以便向特定设备发送推送通知。是否有人可以确认这一点,或者是否有更好的方式发送通知

其次,我还发现,当设备进行软件更新时,这会改变它们的令牌,这是否意味着我们必须有能力更新数据库中的令牌,因为它会经常改变。这也相当重要。是否还有其他时间令牌可能发生更改

最后,节点中是否有用于发送推送通知的好库


提前谢谢

您必须将通知accessToken发送到服务器,这是要传递通知的类似地址。您不必担心accesstoken的变化,因为您必须在每次登录时发送它,这样新更新的accesstoken也会附加到服务器中。您必须像这样在Appdelegate中注册远程通知,然后在登录API中将nsuserdefault中保存的令牌发送到服务器

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.


    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
      UIApplication.sharedApplication().registerUserNotificationSettings(settings)
    UIApplication.sharedApplication().registerForRemoteNotifications()
    return true
}

//Called if successfully  registered for APNS.
 func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    // let deviceTokenString = NSString(format: "%@", deviceToken) as String

    var tokenStr = deviceToken.description
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString("<", withString: "", options: [], range: nil)
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString(">", withString: "", options: [], range: nil)
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString(" ", withString: "", options: [], range: nil)
    print(deviceToken.description)
    print(tokenStr)
    //save the token in NSUserDefaults
    NSUserDefaults.standardUserDefaults().setObject(deviceTokenString, forKey: "deviceToken")


}

//Called if unable to register for APNS.
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {

    print(error)

}
func应用程序(应用程序:UIApplication,didfishlaunchingwithoptions启动选项:[NSObject:AnyObject]?)->Bool{
//应用程序启动后自定义的覆盖点。
let settings=UIUserNotificationSettings(FORTYPE:[.Alert、.Badge、.Sound],类别:nil)
UIApplication.sharedApplication().registerUserNotificationSettings(设置)
UIApplication.sharedApplication().registerForRemoteNotifications()
返回真值
}
//如果成功注册APN,则调用。
func应用程序(应用程序:UIApplication,DidRegisterForRemotionTificationswithDeviceToken deviceToken:NSData){
//让deviceTokenString=NSString(格式:“%@”,deviceToken)作为字符串
var tokenStr=deviceToken.description
tokenStr=tokenStr.stringByReplacingOccurrencesOfString(“,带字符串:”,选项:[],范围:nil)
tokenStr=tokenStr.stringByReplacingOccurrencesOfString(“,带字符串:”,选项:[],范围:nil)
打印(deviceToken.description)
打印(标记STR)
//将令牌保存在NSUserDefaults中
NSUserDefaults.standardUserDefaults().setObject(deviceTokenString,forKey:“deviceToken”)
}
//如果无法注册APN,则调用。
func应用程序(应用程序:UIApplication,DIDFailToRegister for RemoteNotifications,错误:N错误){
打印(错误)
}

设备令牌是向应用程序发送推送通知的密钥 在特定设备上。设备令牌可以更改,因此您的应用程序需要 每次启动时重新注册,并将收到的令牌传递回 到您的服务器。如果无法更新设备令牌,请选择remote 通知可能无法到达用户的设备。装置 当用户将备份数据恢复到新服务器时,令牌始终会更改 或重新安装操作系统。迁移时 将数据传输到新设备或计算机时,用户必须启动应用程序一次 然后才能将远程通知发送到该设备


谢谢你的回答,但我想我还是想知道,如果我想在两个人之间发送通知,我是否仍然存储在我的数据库中?感谢您必须维护数据库,即使是在两个人之间,当用户重新安装ios 9后的应用程序或恢复其手机时,accesstoken会发生更改,并且一个人可以拥有多台设备。因此,您必须维护数据库。如果您必须在每次启动时更新设备令牌,并且应该立即将其发送给提供商,为什么要将其保存为默认值?此方法不会在每次午餐中生成不同的令牌,所以,如果您保存它,您可以将该令牌与新令牌进行比较,并仅在其发生更改时将其发送到服务器。(优化)