iphone - How to access the Device token from didRegisterForRemoteNotificationsWithDeviceToken to my ViewDidLoad method -
i know basic need pull device token , store in string , put(display) on label on viewdidload method. might posible solution? im new on ios development. should use global variable? or posible solution?
this code.
appdelegate.m
- (void)application:(uiapplication *)app didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken { nsstring *str = [nsstring stringwithformat:@"device token=%@",devicetoken]; nslog(@"%@", str); //get string , display on viewdidload method. }
please me. how use global variable access string?
on viewcontroller.m class
- (void)viewdidload { [super viewdidload]; nsstring *gettoken = @"token appdelegate"; }
something that.
you can store token user defaults:
[[nsuserdefaults standarduserdefaults] setvalue:str forkey:@"device_token"];
and in viewdidload:
nsstring *gettoken = [[nsuserdefaults standarduserdefaults] stringforkey:@"device_token"];
but there other approaches: global variable, persistence layer, nsnotification
, , on.
edit:
here have info how register standard user defaults.
edit2:
in order obtain token string, following
nsstring *devicetokenstring = [devicetoken description]; devicetokenstring = [devicetokenstring stringbytrimmingcharactersinset:[nscharacterset charactersetwithcharactersinstring:@"<>"]]; devicetokenstring = [devicetokenstring stringbyreplacingoccurrencesofstring:@" " withstring:@""];
then, in devicetokenstring
end having full value without whitespaces or other character. ready trigger push notifications.
Comments
Post a Comment