技术类iOS开发攻城狮的集散地iOS大咖说

iOS12 一些问题的解决方案

2018-10-18  本文已影响52人  DDY
Multiple commands produce 'xxx/Info.plist'

原因:项目中存在重复命名的info.plist文件

方案:

library not found for -l”stdc++.6.0.9

原因:Xcode10去除了C++6.0.9的支持

方案:

WebView播放视频返回后状态栏不见了

原因:视频播放完成主window成为KeyWindow的时候仍隐藏着UIStatusBar

方案:

- (void)videoPlayerFinishedToShowStatusBar {
    if (@available(iOS 12.0, *)) {
        [[NSNotificationCenter defaultCenter] addObserverForName:UIWindowDidBecomeKeyNotification
                                                          object:self.window
                                                           queue:[NSOperationQueue mainQueue]
                                                      usingBlock:^(NSNotification * _Nonnull note) {
                                                          [[UIApplication sharedApplication] setStatusBarHidden:NO
                                                                                                  withAnimation:UIStatusBarAnimationNone];
                                                      }];
    }
}
wifi获取SSID(wifi名称)失败

原因:需要加权限

方案:

statusBar结构变化导致原来通过状态栏获取网络连接信息代码crash

方案:

+ (NSString *)getIphoneXNetWorkStates {    
    UIApplication *app = [UIApplication sharedApplication];
    id statusBar = [[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"statusBar"];
    id one = [statusBar valueForKeyPath:@"regions"];
    id two = [one valueForKeyPath:@"trailing"];
    NSArray *three = [two valueForKeyPath:@"displayItems"];
    NSString *state = @"无网络";
    for (UIView *view in three) {
        //alert: iOS12.0 情况下identifier的变成了类"_UIStatusBarIdentifier"而不是NSString,所以会在调用“isEqualToString”方法时发生crash,
        //修改前
//        NSString *identifier = [view valueForKeyPath:@"identifier"];
        //修改后
        NSString *identifier = [[view valueForKeyPath:@"identifier"] description];
        if ([identifier isEqualToString:@"_UIStatusBarWifiItem.signalStrengthDisplayIdentifier"]) {
            id item = [view valueForKeyPath:@"_item"];

            //alert: 这个问题和上边一样itemId是_UIStatusBarIdentifier 类型,不是string
            NSString *itemId = [[item valueForKeyPath:@"identifier"] description];
            if ([itemId isEqualToString:@"_UIStatusBarWifiItem"]) {
                state = @"WIFI";
            }
            state = @"不确定";

        } else if ([identifier isEqualToString:@"_UIStatusBarCellularItem.typeDisplayIdentifier"]) {
            UIView *statusBarStringView = [view valueForKeyPath:@"_view"];
            // 4G/3G/E
            state = [statusBarStringView valueForKeyPath:@"text"];
        }

    }

    return state;
}
上一篇下一篇

猜你喜欢

热点阅读