Saturday, 15 June 2013

parse.com - Parse SDK iOS - Push notifications only appear when app is in foreground -



parse.com - Parse SDK iOS - Push notifications only appear when app is in foreground -

i'm using parse api send force notifications between mobile ios devices. when app in background notifications don't arrive.

things i've checked:

-settings of app receive notifications set

-required background modes set

-app capabilities set

-registering notifications done after facebook authentication

- (void) authenticateuserwithfacebook { nsarray *permissionsarray = @[@"user_relationships",@"user_friends",@"read_friendlists",@"publish_actions"]; [pffacebookutils loginwithpermissions:permissionsarray block:^(pfuser *user, nserror *error) { if (!user) { if (!error) { nslog(@"uh oh. user cancelled facebook login."); } else { nslog(@"uh oh. error occurred: %@", error); [[pffacebookutils session] closeandcleartokeninformation]; [[pffacebookutils session] close]; [[fbsession activesession] closeandcleartokeninformation]; [[fbsession activesession] close]; [fbsession setactivesession:nil]; [pfuser logout]; [fbsession renewsystemcredentials:^(acaccountcredentialrenewresult result, nserror *error) { nslog(@"%@",error); [self authenticateuserwithfacebook]; }]; } } else if (user.isnew) { nslog(@"user facebook signed , logged in!"); [fbrequestconnection startformewithcompletionhandler:^(fbrequestconnection *connection, id result, nserror *error) { [[pfuser currentuser] setobject:[result valueforkey:@"id"] forkey:kfbidkey]; [[pfuser currentuser] setobject:[result valueforkey:@"name"] forkey:@"name"]; [[pfuser currentuser] saveinbackground]; }]; [self loadusersfacebookfriends]; if ([[uiapplication sharedapplication] respondstoselector:@selector(registerusernotificationsettings:)]){ [[uiapplication sharedapplication] registerusernotificationsettings:[uiusernotificationsettings settingsfortypes:(uiusernotificationtypesound | uiusernotificationtypealert | uiusernotificationtypebadge) categories:nil]]; } else { [[uiapplication sharedapplication] registerforremotenotificationtypes: (uiusernotificationtypebadge | uiusernotificationtypesound | uiusernotificationtypealert)]; } } else { nslog(@"user facebook logged in!"); [fbrequestconnection startformewithcompletionhandler:^(fbrequestconnection *connection, id result, nserror *error) { [[pfuser currentuser] setobject:[result valueforkey:@"id"] forkey:kfbidkey]; [[pfuser currentuser] setobject:[result valueforkey:@"name"] forkey:@"name"]; [[pfuser currentuser] saveinbackground]; }]; if ([[uiapplication sharedapplication] respondstoselector:@selector(registerusernotificationsettings:)]){ [[uiapplication sharedapplication] registerusernotificationsettings:[uiusernotificationsettings settingsfortypes:(uiusernotificationtypealert | uiusernotificationtypesound | uiusernotificationtypebadge) categories:nil]]; } else{ [[uiapplication sharedapplication] registerforremotenotificationtypes: (uiusernotificationtypebadge | uiusernotificationtypesound | uiusernotificationtypealert)]; } } }]; }

-registered delegate methods fired when starting app

- (void) application:(uiapplication *)application didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken { pfinstallation *currentinstallation = [pfinstallation currentinstallation]; [currentinstallation setdevicetokenfromdata:devicetoken]; [currentinstallation setobject:[[pfuser currentuser] objectforkey:@"fbid"] forkey:kownerkey]; [currentinstallation saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) nslog(@"error %@",error); }]; } - (void) application:(uiapplication *)application didregisterusernotificationsettings:(uiusernotificationsettings *)notificationsettings { [application registerforremotenotifications]; }

-notification delegate method called when in foreground

- (void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult))completionhandler {

-i tried new provisioning profile. same result.

-i've never seen pop notification app wants send notifications.

i found problem was. sending force notifications wrong way. works when app in foreground.

[pfpush sendpushdatatoqueryinbackground:pushquery withdata:gamedata];

this code need use.

[pfpush sendpushmessagetoqueryinbackground:pushquery withmessage:@"test"];

ios parse.com apple-push-notifications

No comments:

Post a Comment