我在AppDelegate中创建此变量来存储deviceToken,然后将其传递给另一个类
var deviceTokenToPass:NSData?
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
deviceTokenToPass = deviceToken
}
在另一个课程中,我尝试将deviceToken传递给Parse.com,但我在deviceToken的传递值中有异常
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let deviceToken = delegate.deviceTokenToPass
var currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken) // Exception in this line
currentInstallation.channels = ["global"]
currentInstallation.saveInBackground()
当我将其放入AppDelegate但我希望将此数据存储在另一个类中时,它的工作正常吗
答案 0 :(得分:0)
你需要打开它
if let deviceToken = delegate.deviceTokenToPass
{
var currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.channels = ["global"]
currentInstallation.saveInBackground()
}