我正在尝试在安装类中保存用户令牌,但没有任何内容添加到类中。
这是我的app委托中的代码块,用于注册令牌并为该用户创建一行。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// Store the deviceToken in the current Installation and save it to Parse
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
if let username = PFUser.currentUser()?.username {
installation.setObject(username, forKey: "user")
}
installation.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in
if (error == nil){
print("saved installation")
}else{
print(error)
}
})
}
我将下面的块放在我的配置文件视图中,这是登录后显示的视图控制器。我将其从app delegate中移出,因为我希望用户在登录后被提示允许通知。问题是didRegisterForRemoteNotifications...
未被调用。
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Sound, .Badge], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
答案 0 :(得分:1)
首先想到的是:你在模拟器中运行它吗?如果是,您将无法获得设备令牌,因为模拟器无法处理远程通知。
其次,这一行:
if let user = PFUser.currentUser()? {
installation.setObject(user, forKey: "user")
}
实际应该是:
type Foo struct{
Bar string `json:"bar"`
}
Parse的iOS库尚未移植到Swift,因此目前它还没有处理订阅。