First, you must enable push notifications in your application in Xcode. You can follow Apple’s instructions, or simply click on your project in Xcode, select the "Capabilities" tab, and then flip the switch in the Push Notifications settings.
For Push Notification support, call the specified Tapjoy method in following delegate methods:
// called when the remote notification is registered
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[Tapjoy setDeviceToken:deviceToken];
}
// called when the user get push message while playing the app
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
[Tapjoy setReceiveRemoteNotification:userInfo];
}
Don’t forget to register the push notification service. Otherwise, you will not able to see the confirm dialog for allowing permission.
// Registering for remote notifications
if (NSClassFromString(@"UNUserNotificationCenter")) {
// iOS 10+ Notifications
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
}
}];
} else if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
// iOS 8 - 9 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
For detailed information, please refer to iOS Local and Remote Notification Programming Guide.
Sending push notifications requires an Apple Push Notification Service push certificate. Refer to Local Notifications and Remote Notifications Guide for more information. Once you obtain the certificate, upload it to the Tapjoy Dashboard. Read How to Configure Push Certificates for more information. Please upload your certificate file to by going to "Settings > App Settings" in the Tapjoy dashboard and then selecting "Push Certificate" from the left menu bar.
You can send a custom payload (a string you enter into the dashboard that the user does not see) when sending a push notification with Tapjoy. This custom payload can be any arbitrary string, and your app can parse and react to this string in any way you program your application to respond. Typical use cases include rewarding the user with currency for responding to the push and sending the user to a specific place in the application via a custom URL scheme. For information on how your app can send the custom push payload, please see the custom payload documentation.
To enable your application to read information sent via this method you need to implement some code. Custom payload is set as the p value of userInfo. Considering the purpose, add proper code to didFinishLaunchingWithOptions
and didReceiveRemoteNotification
like following:
// called when the user clicks the push message
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
…
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil) {
NSString* payload = [userInfo objectForKey:@"p"];
if (payload != nil) {
NSLog(@"Tapjoy push notification with payload: %@", payload);
}
}
...
}
// called when the user gets push message while playing the app
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
...
NSString *payload = [userInfo objectForKey:@"p"];
if (payload != nil) {
NSLog(@"Tapjoy push notification with payload: %@", payload);
}
...
}