AppDelegate.m 文件
// iOS 10 Support
-
(void)jpushNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)())completionHandler {
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}// 在处理通知点击逻辑的地方, 发送广播事件
[[NSNotificationCenter defaultCenter] postNotificationName:@"JiguangBroadcastNotification" object:nil userInfo:userInfo];
completionHandler(); // 系统要求执行这个方法}
扩展插件文件CustomPushClickModule.m
// 通过宏 UNI_EXPORT_METHOD_SYNC 将同步方法暴露给 js 端
UNI_EXPORT_METHOD_SYNC(@selector(registerSyncClickHandler:))
/// 同步方法(注:同步方法会在 js 线程执行)
/// @param options js 端调用方法时传递的参数
-
(NSString )registerSyncClickHandler:(NSDictionary )options {
// [[EventBus sharedInstance] subscribeToEventWithName:@"GlobalEvent" handler:^(NSDictionary userInfo) {
// NSString message = userInfo[@"message"];
// NSLog(@"ClassA Received data: %@", message);
// }];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(receiveBroadcastNotification:) name:@"JiguangBroadcastNotification" object:nil];// 同步返回参数给 js 端 注:只支持返回 String 或 NSDictionary (map) 类型
return @"success";
}
- (void)receiveBroadcastNotification:(NSNotification *)notification {
// 处理接收到的通知
}
前端调用
var CustomPushClickModule = uni.requireNativePlugin("CustomPushClickModule")
CustomPushClickModule.registerSyncClickHandler({code:23})