/// Callback for TPNS registration success
/// @param deviceToken: device token generated by APNs
/// @param xgToken: token generated by TPNS. This value is required during message push. TPNS maintains the mapping relationship between this value and the device token generated by APNs.
/// @param error: error message. If `error` is `nil`, the push service has been successfully registered.
- (void)xgPushDidRegisteredDeviceToken:(NSString *)deviceToken xgToken:(NSString *)xgToken error:(NSError *)error {
if (!error) {
NSLog(@"%s, register success, deviceToken:%@, xgToken:%@", __FUNCTION__, deviceToken, xgToken);
} else {
NSLog(@"%s, register failed:%@, deviceToken:%@, xgToken:%@", __FUNCTION__,error.description, deviceToken, xgToken);
}
}
/// Receive callback for notification messages in a unified manner.
/// @param notification: message object
/// @param completionHandler: callback completed.
/// Message type description: if `msgtype` in the `xg` field is `1`, it means notification message; if `msgtype` is `2`, it means silent message.
/// `notification` message object description: there are two types, `NSDictionary` and `UNNotification`. For detailed interpretations, please see the sample code.
- (void)xgPushDidReceiveRemoteNotification:(id)notification withCompletionHandler:(void (^)(NSUInteger))completionHandler {
NSLog(@"[TPNS Demo] receive notification: %@", notification);
}
/// Unified click callback
/// @param response //`UNNotificationResponse` for iOS 10+ and macOS 10.14+, or `NSDictionary` for earlier versions
/// Message type description: if `msgtype` in the `xg` field is `1`, it means notification message; if `msgtype` is `9`, it means local notifications.
- (void)xgPushDidReceiveNotificationResponse:(nonnull id)response withCompletionHandler:(nonnull void (^)(void))completionHandler {
if ([response isKindOfClass:[UNNotificationResponse class]]) {
NSLog(@"[TPNS Demo] click notification: %@", ((UNNotificationResponse *)response).notification.request.content.userInfo);
} else if ([response isKindOfClass:[NSDictionary class]]) {
NSLog(@"[TPNS Demo] click notification: %@", response);
}
completionHandler();
}
Was this page helpful?