|
|
@@ -30,18 +30,17 @@
|
|
|
|
|
|
NSString *NTESCustomNotificationCountChanged = @"NTESCustomNotificationCountChanged";
|
|
|
|
|
|
-@interface NTESNotificationCenter () <NIMSystemNotificationManagerDelegate,NIMNetCallManagerDelegate,
|
|
|
-NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
+@interface NTESNotificationCenter () <NIMSystemNotificationManagerDelegate, NIMNetCallManagerDelegate,
|
|
|
+ NIMRTSManagerDelegate, NIMChatManagerDelegate, NIMBroadcastManagerDelegate>
|
|
|
|
|
|
-@property (nonatomic,strong) AVAudioPlayer *player; //播放提示音
|
|
|
-@property (nonatomic,strong) NTESAVNotifier *notifier;
|
|
|
+@property(nonatomic, strong) AVAudioPlayer *player; //播放提示音
|
|
|
+@property(nonatomic, strong) NTESAVNotifier *notifier;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation NTESNotificationCenter
|
|
|
|
|
|
-+ (instancetype)sharedCenter
|
|
|
-{
|
|
|
++ (instancetype)sharedCenter {
|
|
|
static NTESNotificationCenter *instance = nil;
|
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
@@ -50,18 +49,17 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
return instance;
|
|
|
}
|
|
|
|
|
|
-- (void)start
|
|
|
-{
|
|
|
+- (void)start {
|
|
|
NSLog(@"Notification Center Setup");
|
|
|
}
|
|
|
|
|
|
- (instancetype)init {
|
|
|
self = [super init];
|
|
|
- if(self) {
|
|
|
+ if (self) {
|
|
|
NSURL *url = [[NSBundle mainBundle] URLForResource:@"message" withExtension:@"wav"];
|
|
|
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
|
|
|
_notifier = [[NTESAVNotifier alloc] init];
|
|
|
-
|
|
|
+
|
|
|
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
|
|
|
[[NIMAVChatSDK sharedSDK].netCallManager addDelegate:self];
|
|
|
[[NIMAVChatSDK sharedSDK].rtsManager addDelegate:self];
|
|
|
@@ -72,7 +70,7 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (void)dealloc{
|
|
|
+- (void)dealloc {
|
|
|
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
|
|
|
[[NIMAVChatSDK sharedSDK].netCallManager removeDelegate:self];
|
|
|
[[NIMAVChatSDK sharedSDK].rtsManager removeDelegate:self];
|
|
|
@@ -81,48 +79,43 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
}
|
|
|
|
|
|
#pragma mark - NIMChatManagerDelegate
|
|
|
-- (void)onRecvMessages:(NSArray *)recvMessages
|
|
|
-{
|
|
|
+
|
|
|
+- (void)onRecvMessages:(NSArray *)recvMessages {
|
|
|
NSArray *messages = [self filterMessages:recvMessages];
|
|
|
- if (messages.count)
|
|
|
- {
|
|
|
+ if (messages.count) {
|
|
|
static BOOL isPlaying = NO;
|
|
|
if (isPlaying) {
|
|
|
return;
|
|
|
}
|
|
|
isPlaying = YES;
|
|
|
[self playMessageAudioTip];
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
isPlaying = NO;
|
|
|
});
|
|
|
[self checkMessageAt:messages];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)playMessageAudioTip
|
|
|
-{
|
|
|
+- (void)playMessageAudioTip {
|
|
|
UINavigationController *nav = [ModelRootViewController instance].selectedViewController;
|
|
|
BOOL needPlay = YES;
|
|
|
for (UIViewController *vc in nav.viewControllers) {
|
|
|
- if ([vc isKindOfClass:[MessageViewController class]] || [vc isKindOfClass:[NTESNetChatViewController class]])
|
|
|
- {
|
|
|
+ if ([vc isKindOfClass:[MessageViewController class]] || [vc isKindOfClass:[NTESNetChatViewController class]]) {
|
|
|
needPlay = NO;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (needPlay) {
|
|
|
[self.player stop];
|
|
|
- [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error:nil];
|
|
|
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
|
|
|
[self.player play];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)checkMessageAt:(NSArray<NIMMessage *> *)messages
|
|
|
-{
|
|
|
+- (void)checkMessageAt:(NSArray<NIMMessage *> *)messages {
|
|
|
//一定是同个 session 的消息
|
|
|
NIMSession *session = [messages.firstObject session];
|
|
|
- if ([self.currentSessionViewController.session isEqual:session])
|
|
|
- {
|
|
|
+ if ([self.currentSessionViewController.session isEqual:session]) {
|
|
|
//只有在@所属会话页外面才需要标记有人@你
|
|
|
return;
|
|
|
}
|
|
|
@@ -138,11 +131,9 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (NSArray *)filterMessages:(NSArray *)messages
|
|
|
-{
|
|
|
+- (NSArray *)filterMessages:(NSArray *)messages {
|
|
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
|
|
- for (NIMMessage *message in messages)
|
|
|
- {
|
|
|
+ for (NIMMessage *message in messages) {
|
|
|
// if ([self checkRedPacketTip:message] && ![self canSaveMessageRedPacketTip:message])
|
|
|
// {
|
|
|
// [[NIMSDK sharedSDK].conversationManager deleteMessage:message];
|
|
|
@@ -203,18 +194,19 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
|
|
|
|
|
|
#pragma mark - NIMSystemNotificationManagerDelegate
|
|
|
-- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification{
|
|
|
+
|
|
|
+- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
|
|
|
|
|
|
NSString *content = notification.content;
|
|
|
- if([content isEqualToString:@"恭喜,您有新的订单"]){
|
|
|
- NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:NTESCustomNotificationCountChanged object:nil];
|
|
|
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"订单消息"
|
|
|
- message:content
|
|
|
- delegate:self
|
|
|
- cancelButtonTitle:nil
|
|
|
- otherButtonTitles:@"去查看",nil];
|
|
|
- [alert show];
|
|
|
+ if ([content isEqualToString:@"恭喜,您有新的订单"]) {
|
|
|
+ NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:NTESCustomNotificationCountChanged object:nil];
|
|
|
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"订单消息"
|
|
|
+ message:content
|
|
|
+ delegate:self
|
|
|
+ cancelButtonTitle:nil
|
|
|
+ otherButtonTitles:@"去查看", nil];
|
|
|
+ [alert show];
|
|
|
}
|
|
|
// if (data)
|
|
|
// {
|
|
|
@@ -267,62 +259,41 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
}
|
|
|
|
|
|
#pragma mark - NIMNetCallManagerDelegate
|
|
|
-- (void)onReceive:(UInt64)callID from:(NSString *)caller type:(NIMNetCallMediaType)type message:(NSString *)extendMessage{
|
|
|
|
|
|
+- (void)onReceive:(UInt64)callID from:(NSString *)caller type:(NIMNetCallMediaType)type message:(NSString *)extendMessage {
|
|
|
ModelRootViewController *tabVC = [ModelRootViewController instance];
|
|
|
[tabVC.view endEditing:YES];
|
|
|
UINavigationController *nav = tabVC.selectedViewController;
|
|
|
|
|
|
- if ([self shouldResponseBusy]){
|
|
|
+ if ([self shouldResponseBusy]) {
|
|
|
[[NIMAVChatSDK sharedSDK].netCallManager control:callID type:NIMNetCallControlTypeBusyLine];
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
+ } else {
|
|
|
if ([self shouldFireNotification:caller]) {
|
|
|
- NSString *text = [self textByCaller:caller
|
|
|
- type:type];
|
|
|
+ NSString *text = [self textByCaller:caller type:type];
|
|
|
[_notifier start:text];
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
UIViewController *vc;
|
|
|
switch (type) {
|
|
|
- case NIMNetCallTypeVideo:{
|
|
|
+ case NIMNetCallTypeVideo: {
|
|
|
vc = [[NTESVideoChatViewController alloc] initWithCaller:caller callId:callID];
|
|
|
- }
|
|
|
break;
|
|
|
- case NIMNetCallTypeAudio:{
|
|
|
-// vc = [[NTESAudioChatViewController alloc] initWithCaller:caller callId:callID];
|
|
|
}
|
|
|
+ case NIMNetCallTypeAudio: {
|
|
|
+// vc = [[NTESAudioChatViewController alloc] initWithCaller:caller callId:callID];
|
|
|
break;
|
|
|
+ }
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if (!vc) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
|
|
|
- CATransition *transition = [CATransition animation];
|
|
|
- transition.duration = 0.25;
|
|
|
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
|
|
|
- transition.type = kCATransitionPush;
|
|
|
- transition.subtype = kCATransitionFromTop;
|
|
|
- [nav.view.layer addAnimation:transition forKey:nil];
|
|
|
- nav.navigationBarHidden = YES;
|
|
|
- if (nav.presentedViewController) {
|
|
|
- // fix bug MMC-1431
|
|
|
- [nav.presentedViewController dismissViewControllerAnimated:NO completion:nil];
|
|
|
- }
|
|
|
- vc.hidesBottomBarWhenPushed = YES;
|
|
|
- [nav pushViewController:vc animated:NO];
|
|
|
+ [nav presentViewController:vc animated:YES completion:nil];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)onHangup:(UInt64)callID
|
|
|
- by:(NSString *)user
|
|
|
-{
|
|
|
+ by:(NSString *)user {
|
|
|
[_notifier stop];
|
|
|
}
|
|
|
|
|
|
@@ -364,13 +335,11 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
//}
|
|
|
|
|
|
- (void)onRTSTerminate:(NSString *)sessionID
|
|
|
- by:(NSString *)user
|
|
|
-{
|
|
|
+ by:(NSString *)user {
|
|
|
[_notifier stop];
|
|
|
}
|
|
|
|
|
|
-- (BOOL)shouldResponseBusy
|
|
|
-{
|
|
|
+- (BOOL)shouldResponseBusy {
|
|
|
ModelRootViewController *tabVC = [ModelRootViewController instance];
|
|
|
UINavigationController *nav = tabVC.selectedViewController;
|
|
|
return [nav.topViewController isKindOfClass:[NTESNetChatViewController class]];
|
|
|
@@ -387,14 +356,13 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
//}
|
|
|
|
|
|
#pragma mark - format
|
|
|
-- (NSString *)textByCaller:(NSString *)caller type:(NIMNetCallMediaType)type
|
|
|
-{
|
|
|
- NSString *action = type == NIMNetCallMediaTypeAudio ? @"音频":@"视频";
|
|
|
- NSString *text = [NSString stringWithFormat:@"你收到了一个%@聊天请求",action];
|
|
|
+
|
|
|
+- (NSString *)textByCaller:(NSString *)caller type:(NIMNetCallMediaType)type {
|
|
|
+ NSString *action = type == NIMNetCallMediaTypeAudio ? @"音频" : @"视频";
|
|
|
+ NSString *text = [NSString stringWithFormat:@"你收到了一个%@聊天请求", action];
|
|
|
NIMKitInfo *info = [[NIMKit sharedKit] infoByUser:caller option:nil];
|
|
|
- if ([info.showName length])
|
|
|
- {
|
|
|
- text = [NSString stringWithFormat:@"%@向你发起了一个%@聊天请求",info.showName,action];
|
|
|
+ if ([info.showName length]) {
|
|
|
+ text = [NSString stringWithFormat:@"%@向你发起了一个%@聊天请求", info.showName, action];
|
|
|
}
|
|
|
return text;
|
|
|
}
|
|
|
@@ -411,23 +379,20 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
// return text;
|
|
|
//}
|
|
|
|
|
|
-- (BOOL)shouldFireNotification:(NSString *)callerId
|
|
|
-{
|
|
|
+- (BOOL)shouldFireNotification:(NSString *)callerId {
|
|
|
//退后台后 APP 存活,然后收到通知
|
|
|
BOOL should = YES;
|
|
|
-
|
|
|
+
|
|
|
//消息不提醒
|
|
|
- id<NIMUserManager> userManager = [[NIMSDK sharedSDK] userManager];
|
|
|
- if (![userManager notifyForNewMsg:callerId])
|
|
|
- {
|
|
|
+ id <NIMUserManager> userManager = [[NIMSDK sharedSDK] userManager];
|
|
|
+ if (![userManager notifyForNewMsg:callerId]) {
|
|
|
should = NO;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//当前在正处于免打扰
|
|
|
- id<NIMApnsManager> apnsManager = [[NIMSDK sharedSDK] apnsManager];
|
|
|
+ id <NIMApnsManager> apnsManager = [[NIMSDK sharedSDK] apnsManager];
|
|
|
NIMPushNotificationSetting *setting = [apnsManager currentSetting];
|
|
|
- if (setting.noDisturbing)
|
|
|
- {
|
|
|
+ if (setting.noDisturbing) {
|
|
|
NSDate *date = [NSDate date];
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
NSDateComponents *components = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:date];
|
|
|
@@ -436,13 +401,11 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
NSInteger end = setting.noDisturbingEndH * 60 + setting.noDisturbingEndM;
|
|
|
|
|
|
//当天区间
|
|
|
- if (end > start && end >= now && now >= start)
|
|
|
- {
|
|
|
+ if (end > start && end >= now && now >= start) {
|
|
|
should = NO;
|
|
|
}
|
|
|
- //隔天区间
|
|
|
- else if(end < start && (now <= end || now >= start))
|
|
|
- {
|
|
|
+ //隔天区间
|
|
|
+ else if (end < start && (now <= end || now >= start)) {
|
|
|
should = NO;
|
|
|
}
|
|
|
}
|
|
|
@@ -452,14 +415,12 @@ NIMRTSManagerDelegate,NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
|
|
|
|
|
|
|
|
|
#pragma mark - Misc
|
|
|
-- (NIMSessionViewController *)currentSessionViewController
|
|
|
-{
|
|
|
+
|
|
|
+- (NIMSessionViewController *)currentSessionViewController {
|
|
|
UINavigationController *nav = [ModelRootViewController instance].selectedViewController;
|
|
|
- for (UIViewController *vc in nav.viewControllers)
|
|
|
- {
|
|
|
- if ([vc isKindOfClass:[NIMSessionViewController class]])
|
|
|
- {
|
|
|
- return (NIMSessionViewController *)vc;
|
|
|
+ for (UIViewController *vc in nav.viewControllers) {
|
|
|
+ if ([vc isKindOfClass:[NIMSessionViewController class]]) {
|
|
|
+ return (NIMSessionViewController *) vc;
|
|
|
}
|
|
|
}
|
|
|
return nil;
|