日志文档--网络鉴权顺序逻辑

2017-02-27  本文已影响25人  黑羽肃霜

百度地图打开时的鉴权问题

appdelegate中需要添加设定的授权。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件,请设定     generalDelegate参数
    BOOL ret = [_mapManager start:BAIDU_KEY generalDelegate:self];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
    // Add the navigation controller's view to the window and display.

    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

百度地图的sdk需要完成鉴权的操作。即为BOOL ret = [_mapManager start:BAIDU_KEY generalDelegate:self];,但是此时有一个代理需要完成鉴权的操作。如下:

#pragma mark 百度地图代理
-(void)onGetNetworkState:(int)iError {
    if (0 == iError)
        NSLog(@"联网成功");
    else
        NSLog(@"onGetNetworkState %d",iError);
}
-(void)onGetPermissionState:(int)iError {
    if (0 == iError)
        NSLog(@"授权成功");
    else
        NSLog(@"onGetPermissionState %d",iError);
}

这就造成了,我发起实际的命令操作时,鉴权还没有完成

逻辑梳理

鉴权和网络数据申请是分不开的。
整体的实现思路如下:

    app.accessCompleteBlk = ^(BOOL result){
        if (result == YES) {
            [self setBaiduRelatedDelegate];
            [[DataUtil managerCenter] updateAllInfoWithSucBlk:^{
                [[BaiduDistrictTool shareInstance] generateOverlaysFromPlist];
                self.isAccess = YES;
                [[NSNotificationCenter defaultCenter] postNotificationName:GUIDE_MODE_RADIO
                                                                    object:[NSNumber numberWithInt:NEARBY_GUIDE_MODE]];
                [self dismissTip];
            } failBlk:^(NSError *err) {
                XLog(@"信息请求失败,错误信息 = %@",err.domain);
                [self dismissTip];
                HUD_DATA_WARNING;
            }];
        } else {
            [self dismissTip];
            HUD_ACCESS_WARNING;
        }
    };

鉴权成功后,执行以下逻辑:

-(void)updateAllInfoWithSucBlk:(SucBlk)sucBlk
                       failBlk:(FailBlk)failBlk {
    plistManager *manager = [[plistManager alloc] initWithPlistName:PLIST_NAME];
    //1.1.从沙盒中取出行政区域边界信息plist用于绘制。如果plist不存在,就创建一个
    if ([manager ifPlistExist] == NO)
        [manager createPlist];
    //1.2读取这个plist文件
    NSDictionary *dict = [manager readPlist];
    if (dict.count == 0) {
        [[BaiduDistrictTool shareInstance] updateDistrictPlistWithSuccessBlk:^{
            //调试用,读plist
            NSDictionary *dict = [manager readPlist];
            XLog(@"空的plist重新获取数据后,读到的plist = %@",dict);

            // 2.1 到这一步,说明已读到正确的信息,继续请求站点信息
            [[StationInfo shareInstance] updateAllStationsInfoWithSuccessBlk:sucBlk
                                                                     FailBlk:failBlk];
        } FailBlk:failBlk];
    } else {// 3.2 已经读到正确的信息,继续获取站点信息
        [[StationInfo shareInstance] updateAllStationsInfoWithSuccessBlk:sucBlk
                                                                 FailBlk:failBlk];
    }
}
上一篇下一篇

猜你喜欢

热点阅读