AccessID 和 AccessKEY。pod 'TPNS-macOS'
* XG_SDK_Cloud_macOS.framework* XGMTACloud_macOS.framework* UserNotifications.framework(10.14+)
TARGETS->General->Frameworks,Libraries,and Embedded Content选项下Embed选择Embed&Sign 如下图:


Build Settings->Other Linker Flags添加编译参数 -ObjC。

(void)applicationDidFinishLaunching:(NSNotification *)aNotification { /// 打开 Debug 模式,即可在终端查看详细的移动推送 TPNS Debug 信息,方便定位问题。 // [[XGPush defaultManager] setEnableDebug:YES]; [XGPush defaultManager].launchOptions = [[aNotification userInfo] mutableCopy]; [[XGPush defaultManager] startXGWithAccessID:TPNS_ACCESS_ID accessKey:TPNS_ACCESS_KEY delegate:self]; }
AppDelegate中选择实现 XGPushDelegate 协议中的方法:/// 注册推送服务成功回调 /// @param deviceToken APNs 生成的Device Token /// @param xgToken TPNS 生成的 Token,推送消息时需要使用此值。TPNS 维护此值与APNs 的 Device Token的映射关系 /// @param error 错误信息,若error为nil则注册推送服务成功(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); } }// 统一收到通知消息的回调 /// @param notification 消息对象 /// @param completionHandler 完成回调 /// 区分消息类型说明:xg字段里的msgtype为1则代表通知消息msgtype为2则代表静默消息 /// notification消息对象说明:有2种类型NSDictionary和UNNotification具体解析参考示例代码(void)xgPushDidReceiveRemoteNotification:(id)notification withCompletionHandler:(void (^)(NSUInteger))completionHandler { NSLog(@"[TPNS Demo] receive notification: %@", notification); } /// 统一点击回调 /// @param response 如果iOS 10+/macOS 10.14+则为UNNotificationResponse,低于目标版本则为NSDictionary /// 区分消息类型说明:xg字段里的msgtype为1则代表通知消息,msgtype为9则代表本地通知(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(); }
javascript[TPNS] Current device token is 2117b45c7e32bcdae2939f******57e420a376bdd44cf6f58613129d2065370[TPNS] Current TPNS token is 0304b8f5d4e*****0af06b37d8b850d95606[TPNS] The server responds correctly, registering device successfully
objective-c//获取 TPNS 生成的 Token[[XGPushTokenManager defaultTokenManager] xgTokenString];//获取 APNs 生成的 DeviceToken[[XGPushTokenManager defaultTokenManager] deviceTokenString];
文档反馈