iOS发送本地通知
来源:互联网 发布:淘宝二手iphone店铺 编辑:程序博客网 时间:2024/06/14 00:45
//发送本地推送,使用环信sdk- (void)showNotificationWithMessage:(EMMessage *)message{ EMPushOptions *options = [[EMClient sharedClient] pushOptions]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [NSDate date]; //触发通知的时间 if (options.displayStyle == EMPushDisplayStyleMessageSummary) { EMMessageBody *messageBody = message.body; NSString *messageStr = nil; switch (messageBody.type) { case EMMessageBodyTypeText:{ messageStr = ((EMTextMessageBody *)messageBody).text; } break; case EMMessageBodyTypeImage:{ messageStr = @"发来一张图片"; } break; case EMMessageBodyTypeLocation:{ messageStr = @"发来ta的位置"; } break; case EMMessageBodyTypeVoice:{ messageStr = @"发来一段语音"; } break; default: break; } NSString *fromNameStr; NSMutableArray *array = [[DBInstance shareInstance] selectCharttingID:message.from]; if([message.from isEqualToString:@"jm_assistant"]){ fromNameStr = @"金脉小助手"; }else if(array.count){ fromNameStr = [array[0] realname]; }else{ fromNameStr = @"新的好友"; } if (message.chatType == EMChatTypeGroupChat) { NSArray *groupArray = [[EMClient sharedClient].groupManager getJoinedGroups]; for (EMGroup *group in groupArray) { if ([group.groupId isEqualToString:message.conversationId]) { break; } } }else if (message.chatType == EMChatTypeChatRoom){ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; NSString *key = [NSString stringWithFormat:@"OnceJoinedChatrooms_%@", [[EMClient sharedClient] currentUsername]]; NSMutableDictionary *chatrooms = [NSMutableDictionary dictionaryWithDictionary:[ud objectForKey:key]]; NSString *chatroomName = [chatrooms objectForKey:message.conversationId]; if(chatroomName){ } }else{ messageStr = [NSString stringWithFormat:@"%@:%@", fromNameStr, messageStr]; } notification.alertBody = [NSString stringWithFormat:@"%@", messageStr]; }else{ notification.alertBody = @"您有一条新消息"; } notification.userInfo = @{@"msgtype":@(1),@"mid":@(0),@"f":message.from}; notification.alertAction = NSLocalizedString(@"open", @"Open"); notification.timeZone = [NSTimeZone defaultTimeZone]; notification.repeatInterval = 0; if([[RKUserDefaults standardUserDefaults] boolForKey:VoiceKey]){ notification.soundName= UILocalNotificationDefaultSoundName; } //发送通知 [[UIApplication sharedApplication] scheduleLocalNotification:notification];}
0 0
- iOS发送本地通知
- ios-王云鹤 发送本地通知
- iOS本地通知——每天固定时间发送通知
- iOS本地通知——每天固定时间发送通知
- iOS本地通知——每天固定时间发送通知
- iOS开发之旅--本地通知的发送与取消
- iOS开发本地通知(每天定点发送消息推送)
- iOS 本地通知 远程通知
- iOS本地通知 远程通知
- iOS本地通知&定时通知
- iOS实现本地通知
- iOS本地通知
- iOS本地通知
- iOS本地通知UILocalNotification
- IOS实现本地通知
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- iOS UILocalNotification本地通知
- 设计模式之结构性模式---外观模式
- 初步实现seetaface的android版本
- UITableView的beginUpdates和endUpdates
- 圆形ImageView
- 自己动手实现一个 Flex 布局框架
- iOS发送本地通知
- java中Map,List与Set的区别
- Android Studio新功能解析,你真的了解Instant Run吗?
- 2016中国软件技术大会六大亮点提前看
- akka 消息 not delivered deadletter
- 手机包含的传感器
- MySQL查询空字段或非空字段(is null和not null)
- 8
- 22种代码的坏味道,一句话概括