Important: Please delete the third-party push SDK and related API interfaces added in the original game before access to prevent conflicts and crashes!
The push module provides remote and local push notification functions.
Game needs to first contact SuperSDK personnel to enable this function and apply for relevant parameters.
Description: After the application is installed for the first time, the push notification permission box will pop up, asking the user whether to allow app notifications.
Note: Both remote and local push notifications need to call this interface first.
Interface Call:
NSUInteger types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;// Push type
[SuperSDK invoke:@"push" funcName:@"registerPush" parameters:@{
@"types" : @(types),// Push type
@"showType" : @"0", // Whether the application displays notifications in the foreground, 0: Displays, 1: Does not display
@"lang" : @"zh-cn" // Language, @"zh-cn" Simplified Chinese, @"zh-tw" Traditional Chinese, @"en" English, @"de" German, @"ru" Russian, @"fr" French, @"es" Spanish, @"pt" Portuguese, @"tr" Turkish, @"pl" Polish, @"ko" Korean, @"ja" Japanese
}];
Description: If this interface is called after a successful login, the user ID is the osdk_user_id value returned by SuperSDK.
Interface Call:
[SuperSDK invoke:@"push" funcName:@"bindUser" parameters:@{
@"osdk_user_id" : @"0060015_123"
}];
Message Callback:
+ (void)handlerCallback:(NSString *)moduleName funcName:(NSString *)funcName parameters:(NSString *)parameters
{
NSLog(@"****** Received Callback\n moduleName : %@,\n funcName : %@,\n parameters : %@", moduleName, funcName, parameters);
NSDictionary *retParam = nil;
if (parameters) {
NSData *jsonData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
retParam = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
}
}
int code = [[retParam objectForKey:@"code"] intValue];
NSDictionary *data = [retParam objectForKey:@"data"];
if ([moduleName isEqualToString:@"push"]) {// Push module callback
if ([funcName isEqualToString:@"receiveRemoteNotification"]) {
NSDictionary *userInfo = [data objectForKey:@"userInfo"]; // Push message
NSString *identifier = [data objectForKey:@"identifier"]; // Will olny have this value if set to action class set, and setting button's identifier!
notifyUserInfo = userInfo;
NSLog(@"Received remote push message, %@", userInfo);
}
}
}
Log Print:
2017-09-21 18:49:08.794658+0800 origin[879:214367] ****** Received Callback
moduleName : push,
funcName : receiveRemoteNotification,
parameters : {
"msg" : "Received remote push",
"data" : {
"userInfo" : {
"aps" : {
"alert" : "This is a test push message!",
"badge" : 1,
"sound" : "default"
}
},
"identifier" : ""
},
"code" : 1
}
2017-09-21 18:49:18.215775+0800 origin[879:214367] Received remote push message, {
aps = {
alert = "\U8fd9\U662f\U4e00\U6761\U63a8\U9001\U6d4b\U8bd5\U6d88\U606f\Uff01";
badge = 1;
sound = default;
};
}
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *fireDate = [format dateFromString:@"2017-12-19 11:07:00"];
NSTimeInterval fireInterval = [fireDate timeIntervalSince1970];
[SuperSDK invoke:@"push" funcName:@"addLocalNotifcation" parameters:@{
@"fireDate" : @(fireInterval), // Notification trigger time, as a timestamp
@"alertTitle" : @"Push title displayed in notification bar", // Push title displayed in notification bar (invalid on iOS8.2 or lower devices!)
@"alertBody". : @"Push content displayed in notification bar", // Push content displayed in notification bar
@"badge" : @(1), // Number of messages displayed on the app
@"identifier" : @"notificationIdentifier1", // Local notification's unique identifier
@"repeat" : @(1), // 0 indicates no repetition, 1 indicates daily repetition, 2 indicates hourly repetition, 3 indicates 1 minute repetition
@"showType" : @"0", // Whether app displays notifications in the foreground, 0: Displays, 1: Does not display
@"isSound" : @"1", // Whether notification sound is enabled, 1: Enabled, 0: Disabled, Default :1
@"soundName" : @"default.caf", // Audio file name extension must be CAF, and the audio duration must be within 30s. Must add audio file to the project, for example: sound.caf
@"userInfo" : @{
@"key" : @"value"
} // Passthrough info
}];
Interface Callback:
+ (void)handlerCallback:(NSString *)moduleName funcName:(NSString *)funcName parameters:(NSString *)parameters
{
NSLog(@"****** Received Callback\n moduleName : %@,\n funcName : %@,\n parameters : %@", moduleName, funcName, parameters);
NSDictionary *retParam = nil;
if (parameters) {
NSData *jsonData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
retParam = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
}
}
int code = [[retParam objectForKey:@"code"] intValue];
NSDictionary *data = [retParam objectForKey:@"data"];
if ([moduleName isEqualToString:@"push"]) {// Push module callback
if ([funcName isEqualToString:@"addLocalNotifcation"]) {// Add local notification callback
NSDictionary *notificationInfo = data;
if (code==BCORE_SUCCESS) {
NSLog(@"Successfully added local notification, notification message:%@", notificationInfo);
}
else {
NSLog(@"Failed to add local notification, reason:%@", desc);
}
}
}
}
Log Print:
2018-12-06 14:23:16.188706+0800 Demo_Mubao[27545:4814437] ****** Received Callback
moduleName: push,
funcName: addLocalNotifcation,
result: {
"msg": "Local notification added successfully",
"data": {
"repeat": 0,
"alertTitle": "Push title displayed in notification bar",
"badge": 1,
"userInfo": {
"key": "value"
},
"isSound": "1",
"alertBody": "Push content displayed in notification bar",
"identifier": "notificationIdentifier1",
"soundName": "sound.caf",
"fireDate": 1543983420,
"showType": "0"
},
"code": 1
}
Note: The registration push interface must be called first, otherwise the local push notification will not get a callback.
Message Callback:
+ (void)handlerCallback:(NSString *)moduleName funcName:(NSString *)funcName parameters:(NSString *)parameters
{
NSLog(@"****** Received Callback\n moduleName : %@,\n funcName : %@,\n parameters : %@", moduleName, funcName, parameters);
NSDictionary *retParam = nil;
if (parameters) {
NSData *jsonData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
retParam = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
}
}
int code = [[retParam objectForKey:@"code"] intValue];
NSDictionary *data = [retParam objectForKey:@"data"];
if ([moduleName isEqualToString:@"push"]) {// Push module callback
if ([funcName isEqualToString:@"receiveLocalNotification"]) {
NSDictionary *notificationInfo = data;
NSLog(@"Received local notification message:%@", notificationInfo);
}
}
}
Log Print:
2018-12-06 14:23:16.232996+0800 Demo_Mubao[27545:4814437] ****** Received Callback
moduleName: push,
funcName: receiveLocalNotification,
result: {
"msg": "Received local notification message",
"data": {
"repeat": 0,
"alertTitle": "Push title displayed in notification bar",
"badge": 1,
"alertBody": "Push content displayed in notification bar",
"identifier": "notificationIdentifier1",
"soundName": "sound.caf",
"fireDate": 1544077396.1952529,
"userInfo": {
"key": "value",
"showType": "0",
"UPush_LocalNotification_Identifier_Key": "notificationIdentifier1"
}
},
"code": 1
}
Interface Call:
[SuperSDK invoke:@"push" funcName:@"fetchLocalNotification" parameters:@{
@"identifier" : @"notificationIdentifier1" // Local notification's unique identifier
}];
Interface Callback:
+ (void)handlerCallback:(NSString *)moduleName funcName:(NSString *)funcName parameters:(NSString *)parameters
{
NSLog(@"****** Received Callback\n moduleName : %@,\n funcName : %@,\n parameters : %@", moduleName, funcName, parameters);
NSDictionary *retParam = nil;
if (parameters) {
NSData *jsonData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
retParam = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
}
}
int code = [[retParam objectForKey:@"code"] intValue];
NSDictionary *data = [retParam objectForKey:@"data"];
if ([moduleName isEqualToString:@"push"]) {// Push module callback
if ([funcName isEqualToString:@"fetchLocalNotification"]) {
NSString *identifier = [data objectForKey:@"identifier"];
if (code==BCORE_SUCCESS) {
NSLog(@"Local notification with the identifier %@ found, notification details:%@", identifier, data);
}
else {
NSLog(@"Local notification with identifier %@ does not exist", identifier);
}
}
}
}
Log Print:
2018-12-06 14:37:48.643562+0800 Demo_Mubao[27569:4816908] ****** Received Callback
moduleName: push,
funcName: fetchLocalNotification,
result: {
"msg": "This notification exists locally",
"data": {
"repeat": 3,
"alertTitle": "Push title displayed in notification bar",
"badge": 1,
"alertBody": "Push content displayed in notification bar",
"soundName": "sound.caf",
"identifier": "notificationIdentifier1",
"fireDate": 1543983420,
"userInfo": {
"key": "value",
"UPush_LocalNotification_Identifier_Key": "notificationIdentifier1",
"showType": "0"
}
},
"code": 1
}
Interface Call:
[SuperSDK invoke:@"push" funcName:@"deleteLocalNotification" parameters:@{
@"identifier" : @"notificationIdentifier1" // Local notification's unique identifier
}];
Interface Call:
[SuperSDK invoke:@"push" funcName:@"deleteAllLocalNotifications" parameters:nil];