xiongzhu 7 tahun lalu
induk
melakukan
707fe19907

+ 22 - 19
model/AppDelegate.m

@@ -168,13 +168,19 @@ NSString *NTESNotificationLogout = @"NTESNotificationLogout";
         default:
             break;
     }
-    [MBProgressHUD showTextHUD:@"超时" inView:self.window hideAfterDelay:1];
-
     [[[NIMSDK sharedSDK] loginManager] logout:^(NSError *error) {
-        [[NSNotificationCenter defaultCenter] postNotificationName:NTESNotificationLogout object:nil];
-        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"下线通知" message:reason delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
-        [alert show];
-        //        [MBProgressHUD showTextHUD:@"超时" inView:self hideAfterDelay:1];
+        UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
+        topWindow.rootViewController = [UIViewController new];
+        topWindow.windowLevel = UIWindowLevelAlert + 1;
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"下线通知" message:reason preferredStyle:UIAlertControllerStyleAlert];
+        [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
+            [self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
+            LoginViewController *loginController = [[LoginViewController alloc] init];
+            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginController];
+            self.window.rootViewController = nav;
+        }]];
+        [topWindow makeKeyAndVisible];
+        [topWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
     }];
 }
 
@@ -185,19 +191,6 @@ NSString *NTESNotificationLogout = @"NTESNotificationLogout";
     //    [[NTESRedPacketManager sharedManager] start];
 }
 
-- (void)registerAPNs {
-    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
-        UIUserNotificationType types = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert;
-        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
-                                                                                 categories:nil];
-        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
-        [[UIApplication sharedApplication] registerForRemoteNotifications];
-    } else {
-        UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge;
-        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
-    }
-}
-
 - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
     [[NIMSDK sharedSDK] updateApnsToken:deviceToken];
     NSLog(@"deviceToken=============%@", deviceToken);
@@ -259,6 +252,7 @@ NSString *NTESNotificationLogout = @"NTESNotificationLogout";
 #pragma mark - misc
 
 - (void)registerPushService {
+    BOOL disableNotification = [[NSUserDefaults standardUserDefaults] boolForKey:@"disableNotification"];
     if (@available(iOS 11.0, *)) {
         UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
         [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError *_Nullable error) {
@@ -281,6 +275,15 @@ NSString *NTESNotificationLogout = @"NTESNotificationLogout";
     PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
     pushRegistry.delegate = self;
     pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
+    
+    NIMPushNotificationSetting *setting =  [[[NIMSDK sharedSDK] apnsManager] currentSetting];
+    setting.noDisturbing = disableNotification;
+    setting.noDisturbingStartH = 0;
+    setting.noDisturbingStartM = 0;
+    setting.noDisturbingEndH = 23;
+    setting.noDisturbingEndM = 59;
+    [[[NIMSDK sharedSDK] apnsManager] updateApnsSetting:setting
+                                             completion:^(NSError *error) {}];
 }
 
 #pragma mark - 登录错误回调

File diff ditekan karena terlalu besar
+ 195 - 264
model/Classes/Controllers/Controller/MessageVC/NTESNetChatViewController.m


+ 64 - 103
model/Classes/Controllers/Controller/MessageVC/NTESNotificationCenter.m

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

+ 17 - 0
model/Classes/Controllers/Controller/SettingsVC/SettingsViewController.m

@@ -24,6 +24,7 @@
 @property (weak, nonatomic) IBOutlet UIImageView *avatar;
 @property (weak, nonatomic) IBOutlet UILabel *nickname;
 @property (weak, nonatomic) IBOutlet UILabel *phone;
+@property (weak, nonatomic) IBOutlet UISwitch *switchNotification;
 
 @property(nonatomic, strong) UIImagePickerController *imagePickerVc;
 @property(nonatomic, copy) NSData *imageData;
@@ -45,6 +46,9 @@
     UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
     nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
     self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
+    
+    BOOL showNotification = ![[NSUserDefaults standardUserDefaults] boolForKey:@"disableNotification"];
+    [self.switchNotification setOn:showNotification];
 }
 
 -(void)backClick{
@@ -177,6 +181,19 @@
     [self.navigationController presentViewController:alert animated:YES completion:nil];
 }
 
+- (IBAction)receiveNotificationChanged:(id)sender {
+    BOOL disableNotification = !((UISwitch*)sender).isOn;
+    NIMPushNotificationSetting *setting =  [[[NIMSDK sharedSDK] apnsManager] currentSetting];
+    setting.noDisturbing = disableNotification;
+    setting.noDisturbingStartH = 0;
+    setting.noDisturbingStartM = 0;
+    setting.noDisturbingEndH = 23;
+    setting.noDisturbingEndM = 59;
+    [[[NIMSDK sharedSDK] apnsManager] updateApnsSetting:setting
+                                             completion:^(NSError *error) {}];
+    [[NSUserDefaults standardUserDefaults] setBool:disableNotification forKey:@"disableNotification"];
+}
+
 - (void)setupLoginViewController {
     [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
     LoginViewController *loginController = [[LoginViewController alloc] init];

+ 4 - 0
model/Classes/Controllers/Controller/SettingsVC/SettingsViewController.xib

@@ -19,6 +19,7 @@
                 <outlet property="section1" destination="jZG-2v-ye3" id="udr-P8-8ZX"/>
                 <outlet property="section2" destination="RMh-Hq-xqF" id="jjG-Q0-IIP"/>
                 <outlet property="section3" destination="WGd-sn-FZj" id="Uzp-oV-D4f"/>
+                <outlet property="switchNotification" destination="arU-7a-FJS" id="JoJ-6l-2vy"/>
                 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
             </connections>
         </placeholder>
@@ -153,6 +154,9 @@
                         <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="arU-7a-FJS">
                             <rect key="frame" x="310" y="14.5" width="51" height="31"/>
                             <color key="onTintColor" red="1" green="0.25098039220000001" blue="0.58431372550000005" alpha="1" colorSpace="calibratedRGB"/>
+                            <connections>
+                                <action selector="receiveNotificationChanged:" destination="-1" eventType="valueChanged" id="HV9-Tz-rlb"/>
+                            </connections>
                         </switch>
                     </subviews>
                     <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

+ 1 - 1
model/ModelHeader.h

@@ -13,7 +13,7 @@
 ///公共url
 #define PublicUrl @"http://app.chmo.net/thmodel"
 #define imageURl @"http://app.chmo.net/thmodel/"
-#define apnsCernameStr @"model"
+#define apnsCernameStr @"modelDev"
 
 // #define PublicUrl @"http://118.190.49.85:8080/thmodel"
 // #define imageURl @"http://118.190.49.85:8080/thmodel/"

+ 1 - 1
model/model.entitlements

@@ -3,6 +3,6 @@
 <plist version="1.0">
 <dict>
 	<key>aps-environment</key>
-	<string>production</string>
+	<string>development</string>
 </dict>
 </plist>

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini