Forum Mobile iOS Push Notifications

Everything mobile goes here.

iOS Push Notifications

Postby frank84 » April 16th, 2014, 11:31 pm

I am trying to set up push notifications on iOS with the Obj-C PlayerIO SDK, but am unsure of how to do it correctly. Here is what I am doing:

Code: Select all
//============================================================================//
// First player logs in with id "First" and registers their endpoint
[PlayerIO authenticateWithGameId:[NSString stringWithUTF8String:gameID]
                     connectionId:@"public"
             authenticationArguments:@{@"userId":loginID]}
               playerInsightSegments:nil
                     successBlock:^(PIOClient* client)
{
   // deviceToken saved from didRegisterForRemoteNotificationsWithDeviceToken
   const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
   NSString* hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
      ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
      ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
      ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

   [client.notifications registerEndpointWithEndpointType:@"ios-push-notifications"
                                  identifier:hexToken
                                configuration:nil
                                    enabled:YES
                                 successBlock:^(){}
                                  errorBlock:^(PIOError* error){}];
}
                       errorBlock:^(PIOError* error){}];
//============================================================================//
// Second player wants to send a notification to first player
NSMutableArray* notifications = [NSMutableArray array];
PIONotification* notif = [[[PIONotification alloc] initWithRecipientUserId:@"First"
   endpointType:@"ios-push-notifications"] autorelease];
[notifications addObject:notif];
[client.notifications sendNotifications:notifications
                     successBlock:^(){}
                       errorBlock:^(PIOError* error){}];
//============================================================================//


The sendNotifications priints out the error: "ERROR: ios-push-notifications: You must specify either 'alert' or 'badgeCount' for iOS push notifications"

How do I set the notification type? Is it done on sending the notification or on registering the endpoint?
frank84
 
Posts: 27
Joined: November 23rd, 2013, 2:09 am

Re: iOS Push Notifications

Postby sqadri » April 18th, 2014, 5:53 pm

Hi,

You need to do the following on your PIONotification object:
[notif setWithKey:@"alert" value:@"Hello World!"];
sqadri
 
Posts: 6
Joined: September 25th, 2013, 6:53 pm

Re: iOS Push Notifications

Postby frank84 » April 18th, 2014, 7:37 pm

Thanks for the reply sqadri, I added the alert line to the code above and am now getting the following error when sending a notification: "An unexpected error occurred inside the Player.IO webservice. Please try again." The registerEndpointWithEndpointType method is completing successfully, but I do not see new endpoints in the playerio dashboard. I have created and uploaded my APNS development and production certificates, which are also being used to make the builds. Additionally I have tried adding the usernames I am logging in with to the Development Users list. The connection type also has Can Send Notifications, Can Register Notification Endpoints and Can Manage Notifications enabled in the dashboard. Should I be able to send notifications with a Development Profile build from Xcode or does it only work with Ad Hoc/App Store builds?
frank84
 
Posts: 27
Joined: November 23rd, 2013, 2:09 am

Re: iOS Push Notifications

Postby sqadri » April 18th, 2014, 11:51 pm

You should be able to send notifications using a development certificate. You need to add the users that have the development version to the Development Users List, which seems like you have done.

For sending notifications, you should create and send GameRequests, as these will automatically generate notifications.
sqadri
 
Posts: 6
Joined: September 25th, 2013, 6:53 pm

Re: iOS Push Notifications

Postby frank84 » May 1st, 2014, 2:11 am

Thanks sqadri, I am now able to send push notifications via PIOGameRequests, while still registering endpoints with PIONotifications. Is there any way to customize the push notification message when sending through PIOGameRequests? If not, is there any plan to add this feature or to get PIONotifications sendNotifications working?

Also, when calling PIONotifications registerEndpointWithEndpointType, what values I put in the configuration dictionary parameter?
frank84
 
Posts: 27
Joined: November 23rd, 2013, 2:09 am

Re: iOS Push Notifications

Postby sqadri » May 1st, 2014, 9:01 pm

Given that it works with GameRequests, we know that the full notification workflow is working, so in theory, the send notification API should also work. I will try to see if I can replicate your issue.
sqadri
 
Posts: 6
Joined: September 25th, 2013, 6:53 pm

Re: iOS Push Notifications

Postby sqadri » May 2nd, 2014, 11:05 pm

I was able to replicate the issue. The issue is being fixed and will be released soon.
sqadri
 
Posts: 6
Joined: September 25th, 2013, 6:53 pm


Return to Mobile



cron