push notification - How to register for GCM in iOS -


i can't seem gcm push notifications working. problem don't know how registration id gcm. can token apn fine. i'm not quite sure next. tried following tutorial not working me. i'm beginner please explicit.

what i'm asking is, after obtaining token apn, do?

thanks in advance. https://developers.google.com/cloud-messaging/ios/client

the registration token given registration handler didregisterforremotenotificationswithdevicetoken

all code below taken gcm sample google.

first, declare handler in application:didfinishlaunchingwithoptions:

_registrationhandler = ^(nsstring *registrationtoken, nserror *error){     if (registrationtoken != nil) {         weakself.registrationtoken = registrationtoken;         nslog(@"registration token: %@", registrationtoken);         nsdictionary *userinfo = @{@"registrationtoken":registrationtoken};         [[nsnotificationcenter defaultcenter] postnotificationname:weakself.registrationkey                                                             object:nil                                                           userinfo:userinfo];     } else {         nslog(@"registration gcm failed error: %@", error.localizeddescription);         nsdictionary *userinfo = @{@"error":error.localizeddescription};         [[nsnotificationcenter defaultcenter] postnotificationname:weakself.registrationkey                                                             object:nil                                                           userinfo:userinfo];     } }; 

call handler in application registration callback:

- (void)application:(uiapplication *)application didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken {     // start gglinstanceid shared instance default config , request registration     // token enable reception of notifications     [[gglinstanceid sharedinstance] startwithconfig:[gglinstanceidconfig defaultconfig]];  _registrationoptions = @{kgglinstanceidregisterapnsoption:devicetoken,                          kgglinstanceidapnsservertypesandboxoption:@yes}; [[gglinstanceid sharedinstance] tokenwithauthorizedentity:_gcmsenderid                                                     scope:kgglinstanceidscopegcm                                                   options:_registrationoptions                                                   handler:_registrationhandler]; } 

the gcm token use "nsstring *registrationtoken" in registration handler.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -