ios - Saving deviceToken to NSUserDefaults -
i trying save device token nsuserdefaults couldn't it.
my code:
func application(application: uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken: nsdata) { var currenttoken=preferences.stringforkey(pushtokenkey) if currenttoken != devicetoken { var datastring = nsstring(data: devicetoken, encoding:nsutf8stringencoding) string? self.preferences.setvalue(datastring, forkey: pushtokenkey) self.preferences.synchronize() } } you can see comparing tokens , if not same updating it. saving nil guess because devicetoken nsdata.
how can resolve problem ?
reason why nil because not able turn nsdata nsstring
by using devicetoken.description string token.
var currenttoken=preferences.stringforkey(pushtokenkey) if currenttoken != devicetoken.description { // here comparing string , nsdata ?? :s var datastring = devicetoken.description self.preferences.setvalue(datastring, forkey: pushtokenkey) self.preferences.synchronize() }
Comments
Post a Comment