From f2cd693fa9acaec754dfa9c26cfb47a65a80c9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 22 Mar 2023 17:17:20 +0800 Subject: [PATCH] iOS: impl iosUsingObject option --- doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m index 4bbfdffa..0a949f7f 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m @@ -46,6 +46,7 @@ - (dispatch_queue_t)syncQueue { - (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise { NSString *biz = [dic optString:@"biz"]; NSString *name = [dic optString:@"name"]; + BOOL usingObject = [dic optBool:@"iosUsingObject"]; if (biz) { name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name]; } @@ -58,13 +59,18 @@ - (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise { options:NSJSONReadingMutableContainers error:&err]; } - [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:dataDic]; + if (usingObject) { + [[NSNotificationCenter defaultCenter] postNotificationName:name object:dataDic userInfo:nil]; + } else { + [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:dataDic]; + } [promise resolve:nil]; } - (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise { NSString *biz = [dic optString:@"biz"]; NSString *name = [dic optString:@"name"]; + BOOL usingObject = [dic optBool:@"iosUsingObject"]; if (biz) { name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name]; } @@ -77,7 +83,7 @@ - (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise { usingBlock:^(NSNotification *note) { __strong typeof(_self) self = _self; DoricPromise *currentPromise = [[DoricPromise alloc] initWithContext:self.doricContext callbackId:callbackId]; - [currentPromise resolve:note.userInfo]; + [currentPromise resolve:usingObject ? note.object : note.userInfo]; }]; dispatch_barrier_async(self.syncQueue, ^{