Browse Source

1.修改iOS Apex Drivers关于Order的通知处理。

Pen Li 7 years ago
parent
commit
91349045d3

+ 36 - 34
Redant Drivers/Apex And Drivers/AppDelegate.m

@@ -10,6 +10,7 @@
 #import "LoginViewController.h"
 #import "RAHomeViewController.h"
 #import <CoreLocation/CoreLocation.h>
+#import "RANavigationController.h"
 
 static const NSInteger OrderTypeNew = 2;
 
@@ -23,13 +24,10 @@ static const NSInteger OrderTypeNew = 2;
 
 #pragma mark - Private
 
-- (void)showHomeVCWithOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 {
+- (void)showHomeVC{
     
     RAHomeViewController *homeVC = [RAHomeViewController viewControllerFromStoryboard];
-    homeVC.gotoDetailID = orderID;
-    homeVC.gotoDetailType = type;
-    homeVC.gotoDetailType2 = type2;
-    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
+    RANavigationController *nav = [[RANavigationController alloc] initWithRootViewController:homeVC];
     self.window.rootViewController = nav;
 }
 
@@ -42,7 +40,7 @@ static const NSInteger OrderTypeNew = 2;
         
         [[RASingleton sharedInstance] loginUser:user password:password];
         
-        [weakSelf showHomeVCWithOrderID:nil type:OrderTypeNew type2:nil];
+        [weakSelf showHomeVC];
     };
     
     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
@@ -106,17 +104,17 @@ static const NSInteger OrderTypeNew = 2;
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     // Override point for customization after application launch.
     
-    NSString *orderID = nil;
-    NSInteger orderType = OrderTypeNew;
-    NSString *orderType2 = nil;
-    if (launchOptions) {
-        NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
-        NSDictionary *aps = [userInfo objectForKey:@"aps"];
-        orderID = [aps objectForKey:@"order-id"];
-        orderType = [[aps objectForKey:@"order-type"] integerValue];
-        orderType2 = [aps objectForKey:@"order-type2"];
-        
-    }
+//    NSString *orderID = nil;
+//    NSInteger orderType = OrderTypeNew;
+//    NSString *orderType2 = nil;
+//    if (launchOptions) {
+//        NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
+//        NSDictionary *aps = [userInfo objectForKey:@"aps"];
+//        orderID = [aps objectForKey:@"order-id"];
+//        orderType = [[aps objectForKey:@"order-type"] integerValue];
+//        orderType2 = [aps objectForKey:@"order-type2"];
+//        
+//    }
     
     // View
     
@@ -124,7 +122,7 @@ static const NSInteger OrderTypeNew = 2;
     self.window.backgroundColor = [UIColor whiteColor];
     
     if (RASingleton.sharedInstance.autoLogin) {
-        [self showHomeVCWithOrderID:orderID type:orderType type2:orderType2];
+        [self showHomeVC];
     } else {
         [self showLoginVC];
     }
@@ -207,21 +205,25 @@ static const NSInteger OrderTypeNew = 2;
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
     NSLog(@"接收到推送内容==%@", response.notification.request.content.userInfo);
     // 点击通知
-    NSDictionary *userInfo = response.notification.request.content.userInfo;
-    NSDictionary *aps = [userInfo objectForKey:@"aps"];
-    NSString *orderID = [aps objectForKey:@"order-id"];
-    NSInteger orderType = [[aps objectForKey:@"order-type"] integerValue];
-    NSString *orderType2 = [aps objectForKey:@"order-type2"];
-    if (!orderType2) {
-        orderType2 = @"";
-    }
-    if (orderID) {
-        [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationGoDetail object:@{@"orderID" : orderID,@"orderType" : @(orderType),@"orderType2" : orderType2}];
-    }
+    
+//    NSDictionary *userInfo = response.notification.request.content.userInfo;
+//    if (userInfo) {
+//
+//        NSDictionary *aps = [userInfo objectForKey:@"aps"];
+//
+//        NSInteger is_order = [[aps objectForKey:@"is-order"] integerValue];
+//        if (is_order) {
+//            [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
+//        }
+//    }
+
     
     completionHandler();
 }
-
+/**
+ 程序处于非运行状态时,收到通知,点击Icon运行程序会调用此方法
+ 程序处于运行状态或后台,收到通知也会调用此方法。
+ */
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
 
     /**
@@ -260,7 +262,7 @@ static const NSInteger OrderTypeNew = 2;
                     "title" : "Notification",
                     "body" : "You have a new order"
                     },
-                "new-order" : 1,
+                "is-order" : 1,
                 "order-id" : "AFS20180530001200",
                 "order-type2" : "Pick Up",
                 "order-type" : 2,
@@ -270,10 +272,10 @@ static const NSInteger OrderTypeNew = 2;
              }
              */
             
-            NSInteger new_order = [[aps objectForKey:@"new-order"] integerValue];
-            if (new_order) {
+            NSInteger is_order = [[aps objectForKey:@"is-order"] integerValue];
+            if (is_order) {
                 
-                [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationNewOrder object:nil];
+                [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationHandleOrder object:nil userInfo:userInfo];
             }
             completionHandler(UIBackgroundFetchResultNewData);
         }

+ 1 - 1
Redant Drivers/Apex And Drivers/Home/More/RAHomeMoreViewController.m

@@ -94,7 +94,7 @@ typedef enum {
 }
 
 - (void)registNotification {
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationNewOrder object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationHandleOrder object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveReloadNotification:) name:RANotificationReloadHome object:nil];
 }
 

+ 0 - 4
Redant Drivers/Apex And Drivers/Home/RAHomeViewController.h

@@ -15,10 +15,6 @@
 
 @property (nonatomic,copy) NSString *currentOrderID;
 
-@property (nonatomic,copy) NSString *gotoDetailID;
-@property (nonatomic,assign) NSInteger gotoDetailType;
-@property (nonatomic,copy) NSString *gotoDetailType2;
-
 #pragma mark - Getter
 
 - (NSUInteger)orderSectionCount;

+ 2 - 7
Redant Drivers/Apex And Drivers/Home/RAHomeViewController.m

@@ -105,11 +105,6 @@
 
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-    
-    if (self.gotoDetailID) {
-        [self pushDetailViewControllerForOrderID:self.gotoDetailID type:self.gotoDetailType type2:self.gotoDetailType2];
-        self.gotoDetailID = nil;
-    }
 }
 
 - (void)dealloc {
@@ -155,9 +150,8 @@
 }
 
 - (void)registNotification {
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationNewOrder object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationHandleOrder object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveReloadNotification:) name:RANotificationReloadHome object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveGoDetailNotification:) name:RANotificationGoDetail object:nil];
 }
 
 #pragma mark - Action
@@ -354,6 +348,7 @@
 }
 
 - (void)receiveGoDetailNotification:(NSNotification *)notification {
+    
     NSDictionary *userInfo = notification.object;
     if (userInfo) {
         NSString *orderID = [userInfo objectForKey:@"orderID"];

+ 2 - 2
Redant Drivers/Apex And Drivers/Login/LoginViewController.m

@@ -74,7 +74,7 @@
     
     [super viewDidAppear:animated];
     
-//    if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeNone) {
+    if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeNone) {
     
         UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Apex & Drivers need background send location" preferredStyle:UIAlertControllerStyleAlert];
         
@@ -96,7 +96,7 @@
         
         [self presentViewController:alertVC animated:YES completion:nil];
         
-//    }
+    }
 }
 
 - (void)didReceiveMemoryWarning {

+ 13 - 0
Redant Drivers/Apex And Drivers/RANavigationController.h

@@ -0,0 +1,13 @@
+//
+//  RANavigationController.h
+//  Apex And Drivers
+//
+//  Created by Jack on 2018/8/31.
+//  Copyright © 2018年 USAI. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RANavigationController : UINavigationController
+
+@end

+ 66 - 0
Redant Drivers/Apex And Drivers/RANavigationController.m

@@ -0,0 +1,66 @@
+//
+//  RANavigationController.m
+//  Apex And Drivers
+//
+//  Created by Jack on 2018/8/31.
+//  Copyright © 2018年 USAI. All rights reserved.
+//
+
+#import "RANavigationController.h"
+#import "RAOrderDetailViewController.h"
+
+@interface RANavigationController ()
+
+@end
+
+@implementation RANavigationController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    
+    [self registNotification];
+}
+
+- (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+- (void)registNotification {
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveHandleOrderNotification:) name:RANotificationHandleOrder object:nil];
+}
+
+- (void)receiveHandleOrderNotification:(NSNotification *)notification {
+ 
+    NSDictionary *userInfo = notification.userInfo;
+    NSDictionary *aps = [userInfo objectForKey:@"aps"];
+    NSString *orderID = [aps objectForKey:@"order-id"];
+    NSInteger orderType = [[aps objectForKey:@"order-type"] integerValue];
+    NSString *orderType2 = [aps objectForKey:@"order-type2"];
+    if (!orderType2) {
+        orderType2 = @"";
+    }
+
+    if (orderID) {
+        [self pushDetailViewControllerForOrderID:orderID type:orderType type2:orderType2];
+    }
+}
+
+- (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 {
+    
+    if (!orderID) {
+        return;
+    }
+    RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
+    detailVC.orderID = orderID;
+    detailVC.orderType = type;
+    detailVC.orderType2 = type2;
+    [self pushViewController:detailVC animated:YES];
+}
+
+@end

+ 1 - 2
Redant Drivers/Apex And Drivers/RANotificationNameCenter.h

@@ -9,9 +9,8 @@
 #import <Foundation/Foundation.h>
 
 
-FOUNDATION_EXTERN NSString * const RANotificationNewOrder;
+FOUNDATION_EXTERN NSString * const RANotificationHandleOrder;
 FOUNDATION_EXTERN NSString * const RANotificationReloadHome;
 FOUNDATION_EXTERN NSString * const RANotificationLogout;
-FOUNDATION_EXTERN NSString * const RANotificationGoDetail;
 FOUNDATION_EXTERN NSString * const RANotificationStopLocation;
 FOUNDATION_EXTERN NSString * const RANotificationStartLocation;

+ 1 - 2
Redant Drivers/Apex And Drivers/RANotificationNameCenter.m

@@ -9,9 +9,8 @@
 #import "RANotificationNameCenter.h"
 
 
-NSString * const RANotificationNewOrder         = @"RANotificationNewOrder";
+NSString * const RANotificationHandleOrder         = @"RANotificationHandleOrder";
 NSString * const RANotificationReloadHome       = @"RANotificationReloadHome";
 NSString * const RANotificationLogout           = @"RANotificationLogout";
-NSString * const RANotificationGoDetail         = @"RANotificationGoDetail";
 NSString * const RANotificationStartLocation    = @"RANotificationStartLocation";
 NSString * const RANotificationStopLocation     = @"RANotificationStopLocation";