美文网首页
关于iOS 10的适配及Xcode 8的变化

关于iOS 10的适配及Xcode 8的变化

作者: 残雪3088 | 来源:发表于2016-09-18 21:56 被阅读1541次

    一、iOS 10

    1、权限

    IOS 10使用隐私功能,必须在info.plist添加相应地权限配置,以及相应的Value(注:Value不能为空)。

    添加相册权限 请求相册权限

    这里是可设置的隐私权限(根据iPhone设置—隐私匹配)

    Privacy - Bluetooth Peripheral Usage Description // 蓝牙共享
    Privacy - Calendars Usage Description // 日历
    Privacy - Camera Usage Description // 相机
    Privacy - Contacts Usage Description // 通讯录
    Privacy - Health Share Usage Description // 健康—读取数据
    Privacy - Health Update Usage Description // 健康—写入数据
    Privacy - HomeKit Usage Description // HomeKit
    Privacy - Location Always Usage Description // 定位—始终
    Privacy - Location Usage Description //
    Privacy - Location When In Use Usage Description // 定位—使用应用期间
    Privacy - Media Library Usage Description // 媒体资料库
    Privacy - Microphone Usage Description // 麦克风
    Privacy - Motion Usage Description // 运动与健身
    Privacy - Music Usage Description //
    Privacy - Photo Library Usage Description // 相片
    Privacy - Reminders Usage Description // 提醒事项
    Privacy - Siri Usage Description // Siri
    Privacy - Speech Recognition Usage Description // 语音识别
    Privacy - TV Provider Usage Description //

    2、推送

    注册推送,在didFinishLaunchingWithOptions中添加注册方法。

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10) {
        // ios10
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {
                // 点击允许
                NSLog(@"注册通知成功");
                [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
                    NSLog(@"%@", settings);
                }];
            } else {
                // 点击不允许
                NSLog(@"注册通知失败");
            }
        }];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        
    } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
        // iOS8 - iOS10
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];
    } else {
        // iOS8以前
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
    }
    

    接收deviceToken,还是在didRegisterForRemoteNotificationsWithDeviceToken

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        NSLog(@"====deviceToken:%@", deviceToken);
    }
    

    接收推送信息,需要实现协议NSUserNotificationCenterDelegate

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { 
        NSLog(@"====应用在前台收到通知:%@", notification);
    }
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
        NSLog(@"====点击通知进入应用:%@", response);
    }
    

    二、Xcode 8 的相关设置

    1、屏蔽无用的log

    com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0

    解决方法:
    Xcode8里边 Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加 OS_ACTIVITY_MODE = Disable

    屏蔽无用log

    2、代码注释不可用

    解决方案:打开终端,输入以下命令,然后重启电脑。

    sudo /usr/libexec/xpccachectl

    3、Xcode 8打开低版本创建的xib、storyboard的问题

    Xcode8打开低版本创建xib的提示

    解决方案:选择相应的Device,然后更新布局的frame即可

    低版本Xcode打开Xcode8创建xib的提示

    解决方案:删除Xib里面的下边一行。

    <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    

    4、打包报错

    Code signing is required for product type 'Application' in SDK 'iOS 10.0'

    解决方案:
    删除所有的Provisioning Profile,重新下载,然后在General重新配置配置开发者账户,并勾选Automatically manage signing

    配置开发者账户

    相关文章

      网友评论

          本文标题:关于iOS 10的适配及Xcode 8的变化

          本文链接:https://www.haomeiwen.com/subject/ccjeettx.html