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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -