zwp vor 4 Monaten
Ursprung
Commit
ededd69dfd
3 geänderte Dateien mit 38 neuen und 11 gelöschten Zeilen
  1. 31 10
      AIIM/AppDelegate.m
  2. 1 1
      AIIM/Common/Defaults/UDManager.h
  3. 6 0
      AIIM/Common/Network/GWebSocket.m

+ 31 - 10
AIIM/AppDelegate.m

@@ -215,7 +215,8 @@
 -(void)setupListener{
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLoginSucc) name:nkonLoginSucc object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLogout) name:nkonLogoutSucc object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addFriend) name:nkonAddFriendNote object:nil];;
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addFriend) name:nkonAddFriendNote object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJoinGroupNote:) name:nkonJoinGroupNote object:nil];
 }
 
 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
@@ -321,20 +322,40 @@
 }
 
 - (void)sendAddFreindNotice {
-    // 发送本地通知
+    NSInteger total = self.badgeCount + self.addFriendBadgeCount + 1;
     UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
     content.title = @"好友申请";
     content.body = @"您收到了新的好友申请";
     content.sound = [UNNotificationSound defaultSound];
-    content.badge = @(self.addFriendBadgeCount);
+    content.badge = @(total);
     content.userInfo = @{
-        @"addFriend":@(1)
+        @"need_present":@(1)
     };
-    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];
+    [self addNotificationRequest:content];
+}
+
+- (void)onJoinGroupNote:(NSNotification *)notice {
+    NSDictionary *dict = notice.object;
+    if (![dict isKindOfClass:NSDictionary.class]) {
+        return;
+    }
     
-    NSString *identifier = [NSString stringWithFormat:@"FriendRequest_%@", [[NSUUID UUID] UUIDString]];
-    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
+    NSInteger total = self.badgeCount + self.addFriendBadgeCount + 1;
+    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
+    content.title = @"Uim消息";
+    content.body = dict[@"content"] ?: @"您有一条新消息";
+    content.sound = [UNNotificationSound defaultSound];
+    content.badge = @(total);
+    content.userInfo = @{
+        @"need_present":@(1)
+    };
     
+    [self addNotificationRequest:content];
+}
+
+- (void)addNotificationRequest:(UNMutableNotificationContent *)content {
+    NSString *identifier = [NSString stringWithFormat:@"FriendRequest_%@", [[NSUUID UUID] UUIDString]];
+    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:nil];
     [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
         if (error) {
             NSLog(@"发送本地通知失败: %@", error);
@@ -685,9 +706,9 @@
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
     
     NSDictionary *userInfo = notification.request.content.userInfo;
-    NSInteger addFriend = [[userInfo objectForKey:@"addFriend"] integerValue];
-    if (addFriend) {
-        // 添加好友通知在app内也要展示
+    NSInteger show = [[userInfo objectForKey:@"need_present"] integerValue];
+    if (show) {
+        // 通知在app内也要展示
         completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner |
                               UNNotificationPresentationOptionSound |
                               UNNotificationPresentationOptionBadge);

+ 1 - 1
AIIM/Common/Defaults/UDManager.h

@@ -28,7 +28,7 @@ static NSString * _Nonnull nkonLogoutSucc = @"nkonLogoutSucc";
 static NSString * _Nonnull nkonNewMessageNote = @"nkonNewMessageNote";
 static NSString * _Nonnull nkonAddFriendNote = @"nkonAddFriendNote";
 static NSString * _Nonnull nkonEXGroupdNote = @"nkonEXGroupdNote";
-
+static NSString * _Nonnull nkonJoinGroupNote = @"nkonJoinGroupNote";
 //oss
 static NSString * _Nonnull nkOSSinfo = @"nkOSSinfo";
 

+ 6 - 0
AIIM/Common/Network/GWebSocket.m

@@ -358,6 +358,12 @@ static NSString *redeady = @"{\"code\":1}";
     [ChatsStore.shareInstance reciveMsg:mutablemsg];//聊天窗信息
     [ChatListStore.shareInstance reciveMsg:[mutablemsg copy]];//聊天窗列表
     [[NSNotificationCenter defaultCenter] postNotificationName:nkonNewMessageNote object:mutablemsg];
+    
+    NSString *messageType = msg[@"messageType"];
+    if ([messageType isEqualToString:MessageType_event]) {
+        [[NSNotificationCenter defaultCenter] postNotificationName:nkonJoinGroupNote object:mutablemsg];
+    }
+
 }
 
 //消息已收到回执