From a8daded81bb1f1da944d99af192144e36d5c05a1 Mon Sep 17 00:00:00 2001 From: pikacode Date: Mon, 27 Mar 2017 16:31:28 +0800 Subject: [PATCH] iOS - fix #220 --- src/ios/Plugins/AppDelegate+JPush.m | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 862b1e7..1d8af8b 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -28,29 +28,27 @@ return [self init_plus]; } -NSDictionary *_launchOptions; +-(void)fireOpenNotification:(NSTimer*)timer{ + if (SharedJPushPlugin) { + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]]; + [timer invalidate]; + } +} +NSDictionary *_launchOptions; -(void)applicationDidLaunch:(NSNotification *)notification{ + if (notification) { if (notification.userInfo) { NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo1.count > 0) { - [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { - if (SharedJPushPlugin) { - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]]; - [timer invalidate]; - } - }]; + [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES]; } + NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (userInfo2.count > 0) { - [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) { - if (SharedJPushPlugin) { - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo2 toJsonString]]; - [timer invalidate]; - } - }]; + [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES]; } } [JPUSHService setDebugMode]; @@ -64,7 +62,6 @@ NSDictionary *_launchOptions; if (![delay boolValue]) { [self startJPushSDK]; } - } }