Просмотр исходного кода

1.修改iOS Apex Drivers推送通知处理。

Pen Li 7 лет назад
Родитель
Сommit
26f1deccb7

+ 28 - 3
Redant Drivers/Apex And Drivers/AppDelegate.m

@@ -17,6 +17,8 @@
 
 @property (nonatomic,strong) CLLocationManager *locationManager;
 
+@property (nonatomic,strong) NSDictionary *currentOrderNotification;
+
 @end
 
 @implementation AppDelegate
@@ -158,8 +160,11 @@
     // 程序被强杀之后收到通知,点击 通知 启动应用
     if (launchOptions && application.applicationState == UIApplicationStateInactive) {
         
-        NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
-        [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+        NSMutableDictionary *userInfo = [[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
+        if (userInfo) {
+            [userInfo setObject:@(YES) forKey:@"go2Detail"];
+            [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+        }
     }
 
     
@@ -174,6 +179,12 @@
         self.uploadManager=[[RAUploadManager alloc] init];
     }
     [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
+    
+    // 程序在后台收到通知后,直接打开程序的情况下弹窗提示
+    if (self.currentOrderNotification) {
+        [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:self.currentOrderNotification];
+        self.currentOrderNotification = nil;
+    }
 }
 
 - (void)applicationWillTerminate:(UIApplication *)application {
@@ -235,6 +246,12 @@
 //    }
 //    [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"isActive: %ld %s",[UIApplication sharedApplication].applicationState,__func__]];
     
+    self.currentOrderNotification = nil;
+    
+    NSMutableDictionary *userInfo = [response.notification.request.content.userInfo mutableCopy];
+    [userInfo setObject:@(YES) forKey:@"go2Detail"];
+    [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+    
     completionHandler();
 }
 
@@ -293,7 +310,15 @@
             NSInteger is_order = [[aps objectForKey:@"is-order"] integerValue];
             if (is_order) {
                 
-                [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+                // 程序在前台,弹窗提示
+                if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
+                    
+                    [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+                    
+                } else {
+                    // 程序在后台,记录下来。当程序重新进入前台时弹窗提示(没有点击通知打开程序的情况)
+                    self.currentOrderNotification = userInfo;
+                }
             }
             completionHandler(UIBackgroundFetchResultNewData);
         }

+ 26 - 19
Redant Drivers/Apex And Drivers/RANavigationController.m

@@ -118,30 +118,37 @@
         orderType2 = @"";
     }
 
+    BOOL go2Detail = [userInfo objectForKey:@"go2Detail"];
+    
 //    [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
     if (orderID) {
         
-       
-        NSString *msg = [aps objectForKey:@"message"];
-        if (msg.length == 0) {
-            msg = [NSString stringWithFormat:@"%@ status changed,view detail?",orderID];
-        }
-        
-        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
-        
-        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        if (go2Detail) {
             
-        }];
-        
-        __weak typeof(self) weakSelf = self;
-        UIAlertAction *detailAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-            [weakSelf pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
-        }];
-        
-        [alertVC addAction:cancelAction];
-        [alertVC addAction:detailAction];
+            [self pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
+        } else {
+            NSString *msg = [aps objectForKey:@"message"];
+            if (msg.length == 0) {
+                msg = [NSString stringWithFormat:@"%@ status changed,view detail?",orderID];
+            }
+            
+            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
+            
+            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                
+            }];
+            
+            __weak typeof(self) weakSelf = self;
+            UIAlertAction *detailAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                [weakSelf pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2 statusNo:statusNo];
+            }];
+            
+            [alertVC addAction:cancelAction];
+            [alertVC addAction:detailAction];
+            
+            [self presentViewController:alertVC animated:YES completion:nil];
+        }
         
-        [self presentViewController:alertVC animated:YES completion:nil];
     }
 }