|
|
@@ -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);
|