@@ -295,14 +295,7 @@ - (void)clearAllNotifications:(FlutterMethodCall*)call result:(FlutterResult)res
295295}
296296
297297- (void )getLaunchAppNotification : (FlutterMethodCall*)call result : (FlutterResult)result {
298- NSDictionary *notification;
299- notification = [_launchNotification objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
300-
301- if ([_launchNotification objectForKey: UIApplicationLaunchOptionsLocalNotificationKey]) {
302- UILocalNotification *localNotification = [_launchNotification objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
303- notification = localNotification.userInfo ;
304- }
305- result (notification);
298+ result (_launchNotification == nil ? @{}: _launchNotification);
306299}
307300
308301- (void )getRegistrationID : (FlutterMethodCall*)call result : (FlutterResult)result {
@@ -406,7 +399,22 @@ - (BOOL)application:(UIApplication *)application
406399
407400 if (launchOptions != nil ) {
408401 _launchNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
402+ _launchNotification = [self jpushFormatAPNSDic: _launchNotification.copy];
403+ }
404+
405+ if ([launchOptions valueForKey: UIApplicationLaunchOptionsLocalNotificationKey]) {
406+ UILocalNotification *localNotification = [launchOptions valueForKey: UIApplicationLaunchOptionsLocalNotificationKey];
407+ NSMutableDictionary *localNotificationEvent = @{}.mutableCopy ;
408+ localNotificationEvent[@" content" ] = localNotification.alertBody ;
409+ localNotificationEvent[@" badge" ] = @(localNotification.applicationIconBadgeNumber );
410+ localNotificationEvent[@" extras" ] = localNotification.userInfo ;
411+ localNotificationEvent[@" fireTime" ] = [NSNumber numberWithLong: [localNotification.fireDate timeIntervalSince1970 ] * 1000 ];
412+ localNotificationEvent[@" soundName" ] = [localNotification.soundName isEqualToString: UILocalNotificationDefaultSoundName] ? @" " : localNotification.soundName ;
409413
414+ if (@available (iOS 8.2 , *)) {
415+ localNotificationEvent[@" title" ] = localNotification.alertTitle ;
416+ }
417+ _launchNotification = localNotificationEvent;
410418 }
411419 return YES ;
412420}
@@ -416,28 +424,13 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
416424}
417425
418426- (void )applicationDidBecomeActive : (UIApplication *)application {
419- // _resumingFromBackground = NO;
420- // Clears push notifications from the notification center, with the
421- // side effect of resetting the badge count. We need to clear notifications
422- // because otherwise the user could tap notifications in the notification
423- // center while the app is in the foreground, and we wouldn't be able to
424- // distinguish that case from the case where a message came in and the
425- // user dismissed the notification center without tapping anything.
426- // TODO(goderbauer): Revisit this behavior once we provide an API for managing
427- // the badge number, or if we add support for running Dart in the background.
428- // Setting badgeNumber to 0 is a no-op (= notifications will not be cleared)
429- // if it is already 0,
430- // therefore the next line is setting it to 1 first before clearing it again
431- // to remove all
432- // notifications.
433427 application.applicationIconBadgeNumber = 1 ;
434428 application.applicationIconBadgeNumber = 0 ;
435429}
436430
437431- (bool )application : (UIApplication *)application
438432didReceiveRemoteNotification : (NSDictionary *)userInfo
439433fetchCompletionHandler : (void (^)(UIBackgroundFetchResult result))completionHandler {
440- // [self didReceiveRemoteNotification:userInfo];
441434
442435 [_channel invokeMethod: @" onReceiveNotification" arguments: userInfo];
443436 completionHandler (UIBackgroundFetchResultNoData);
@@ -461,28 +454,41 @@ - (void)application:(UIApplication *)application
461454
462455
463456
464- - (void )jpushNotificationCenter : (UNUserNotificationCenter *)center willPresentNotification : (UNNotification *)notification withCompletionHandler : (void (^)(NSInteger ))completionHandler {
465-
457+ - (void )jpushNotificationCenter : (UNUserNotificationCenter *)center willPresentNotification : (UNNotification *)notification withCompletionHandler : (void (^)(NSInteger ))completionHandler API_AVAILABLE(ios(10.0 )){
466458
467459 NSDictionary * userInfo = notification.request .content .userInfo ;
468460 if ([notification.request.trigger isKindOfClass: [UNPushNotificationTrigger class ]]) {
469461 [JPUSHService handleRemoteNotification: userInfo];
470- [_channel invokeMethod: @" onReceiveNotification" arguments: userInfo];
462+ [_channel invokeMethod: @" onReceiveNotification" arguments: [ self jpushFormatAPNSDic: userInfo] ];
471463 }
472464
473-
474465 completionHandler (notificationTypes);
475466}
476467
477- - (void )jpushNotificationCenter : (UNUserNotificationCenter *)center didReceiveNotificationResponse : (UNNotificationResponse *)response withCompletionHandler : (void (^)())completionHandler {
468+ - (void )jpushNotificationCenter : (UNUserNotificationCenter *)center didReceiveNotificationResponse : (UNNotificationResponse *)response withCompletionHandler : (void (^)())completionHandler API_AVAILABLE(ios( 10.0 )) {
478469 NSDictionary * userInfo = response.notification .request .content .userInfo ;
479470 if ([response.notification.request.trigger isKindOfClass: [UNPushNotificationTrigger class ]]) {
480471 [JPUSHService handleRemoteNotification: userInfo];
481- // [[NSNotificationCenter defaultCenter] postNotificationName:@"kJPFOpenNotification" object:userInfo];
482- [_channel invokeMethod: @" onOpenNotification" arguments: userInfo];
483-
472+ [_channel invokeMethod: @" onOpenNotification" arguments: [self jpushFormatAPNSDic: userInfo]];
484473 }
485474 completionHandler ();
486475}
487476
477+ - (NSMutableDictionary *)jpushFormatAPNSDic : (NSDictionary *)dic {
478+ NSMutableDictionary *extras = @{}.mutableCopy ;
479+ for (NSString *key in dic) {
480+ if ([key isEqualToString: @" _j_business" ] ||
481+ [key isEqualToString: @" _j_msgid" ] ||
482+ [key isEqualToString: @" _j_uid" ] ||
483+ [key isEqualToString: @" actionIdentifier" ] ||
484+ [key isEqualToString: @" aps" ]) {
485+ continue ;
486+ }
487+ extras[key] = dic[key];
488+ }
489+ NSMutableDictionary *formatDic = dic.mutableCopy ;
490+ formatDic[@" extras" ] = extras;
491+ return formatDic;
492+ }
493+
488494@end
0 commit comments