Skip to content

Commit

Permalink
fix backgroup notification event fire twice
Browse files Browse the repository at this point in the history
  • Loading branch information
huangminlinux committed Jan 31, 2018
1 parent 4f0c186 commit 7f2179f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ios/Plugins/AppDelegate+JPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NS
}

-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = @[].mutableCopy;
NSMutableDictionary *userInfo = @{}.mutableCopy;

if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo];
Expand All @@ -169,6 +169,10 @@ -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
userInfo[@"identifier"] = notification.request.identifier;
}

if ([userInfo[@"aps"][@"content-available"] isEqualToNumber:@(1)]) {// content-available 当用户开启后台推送是,防止触发两次事件
return;
}

[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
Expand Down

0 comments on commit 7f2179f

Please sign in to comment.