In this tutorial we show how to create a push-enabled application.

 

 Our thanks goes to Matteo Morelli for the development of the Swift version of the sample project.

 

We assume that the developer already owns an account into the ArenaDaemon web platform and

owns the knowledge for creating a new application and retrieving the correspondent appKey.

Moreover, we assume that a valid push certificate has already been uploaded and setup

in order to make the push service working.

 

For more information about how to create a developer account and for setup a new application,

please refer to the chapter "Create an appKey".

For more information about how to setup a push certificate,

please refer to the chapter "Push Notification : Setup".

 

The implementation steps to perform for building a working push enabled application are few and

very simple.

 

The first step is the initial SDK setup and involves only the AppDelegate class.

More in depth the following lines of code have to be added :

 

 

 In 

- (BOOL)application:(UIApplication *)application

    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 

 

- (BOOL)application:(UIApplication *)application

        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        ...

        ...

        [BDArenaConnector initializeWithAppKey:@"<YOUR_APP_KEY>" 

                 runInSandboxEnvironment:YES];

 

        // request auth

        [[BDArenaConnector getInstance] requestAuth];

 

        // register for remote notifications

        [[UIApplicationsharedApplication] registerUserNotificationSettings:

                [UIUserNotificationSettingssettingsForTypes:

                (UIUserNotificationTypeSound |

                                UIUserNotificationTypeAlert

                                        UIUserNotificationTypeBadge)

                categories:nil]];

        [[UIApplicationsharedApplication] registerForRemoteNotifications];

 

        // send feedback

        [[BDArenaConnector getInstance].pushConnector 

                feedbackServiceDidFinishLaunchingWithOptions:launchOptions];

        ...

        ...

}

 

 

 

In

- (void)application:(UIApplication*)application

    didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

 

 

- (void)application:(UIApplication *)application

        didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

        ...

        [[BDArenaConnector getInstance]

                registerDeviceForPushNotifications:deviceToken];

        ... 

}

 

 

 

In

- (void) application:(UIApplication *)application

    didReceiveRemoteNotification:(NSDictionary *)userInfo

 

 

- (void)application:(UIApplication *)application

        didReceiveRemoteNotification:(NSDictionary *)userInfo{

        ...

        // send feedback

        [[BDArenaConnector getInstance].pushConnector 

                feedbackServiceDidReceiveRemoteNotification:userInfo];

 

        // handle push notification displaying a default system alert.

        // the developer can implement his own notification management

        // removing the following method...

        [[BDArenaConnector getInstance].pushConnector 

                handlePush:userInfo

                withPresentingController:self.window.rootViewController

                withActionButtonHandler:^{

                        ;

                } withCancelButtonHandler:^{

                        ;

                }];

        ... 

}

 

 

 

With these basic calls, the application will be completely able

to manage incoming push notifications. For the sending operations, two methods are available : 

sendPush:ToPlayerWithAuid: and sendPush:ToChannel:

 

 

Moreover, the local player can subscribe and unsubscribe to and from channels simply calling 

subscribeToChannel: and unsubscribeFromChannel:

 

 

Sample project

Download the sample project for this tutorial [Objective-C | Swift].