一、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
2、代码注释不可用
解决方案:打开终端,输入以下命令,然后重启电脑。
sudo /usr/libexec/xpccachectl
3、Xcode 8打开低版本创建的xib、storyboard的问题
解决方案:选择相应的Device,然后更新布局的frame即可
解决方案:删除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
。