Эх сурвалжийг харах

解决普通私聊消息在前台也展示推送问题

zwp 4 сар өмнө
parent
commit
917d5fab39
1 өөрчлөгдсөн 13 нэмэгдсэн , 4 устгасан
  1. 13 4
      AIIM/AppDelegate.m

+ 13 - 4
AIIM/AppDelegate.m

@@ -352,7 +352,9 @@
     content.body = @"您收到了新的好友申请";
     content.sound = [UNNotificationSound defaultSound];
     content.badge = @(self.addFriendBadgeCount);
-    
+    content.userInfo = @{
+        @"addFriend":@(1)
+    };
     UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];
     
     NSString *identifier = [NSString stringWithFormat:@"FriendRequest_%@", [[NSUUID UUID] UUIDString]];
@@ -706,9 +708,16 @@
 
 #pragma mark 用户点击消息推送或滑动
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
-    completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner |
-                          UNNotificationPresentationOptionSound |
-                          UNNotificationPresentationOptionBadge);
+    
+    NSDictionary *userInfo = notification.request.content.userInfo;
+    NSInteger addFriend = [[userInfo objectForKey:@"addFriend"] integerValue];
+    if (addFriend) {
+        // 添加好友通知在app内也要展示
+        completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner |
+                              UNNotificationPresentationOptionSound |
+                              UNNotificationPresentationOptionBadge);
+    }
+    
 }
 
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {