iPhone7的售卖意味着一波新技术的来袭。针对最新的iOS10,开发者们需要注意些什么呢
iOS10
1.推送
Targets->Capabilities->Push Notificaitions需开启
若需监听app推送权限,则项目里添加
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(willEnterForegroundNotification) name:UIApplicationWillEnterForegroundNotification object:nil];
具体实现
- (BOOL)userIsOpenPushNotification{
UIUserNotificationSettings *userNotificationSetting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if(userNotificationSetting.types == UIUserNotificationTypeNone) {
// 已关闭
return NO;
}
else{
// 已开启
return YES;
}
}
2.URL Scheme
iOS10移除了所有系统设置的URL Scheme,因此无法再跳转至系统设置页面(WIFI、定位等),当需要跳转至应用设置界面,则添加
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Xcode8
1.真机调试8.0以下版本
进入设备支持环境路径
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
将6、7版本的文件夹复制到Xcode8对应文件夹内
修改Xcode编译环境的plist文件
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
将SDKSettings.plist修改为读写模式并对其添加支持版本(排序需由小到大)
<key>DEPLOYMENT_TARGET_SUGGESTED_VALUES</key>
<array>
<string>6.0</string>
<string>6.1</string>
<string>7.0</string>
<string>7.1</string>
</array>
2.注释失效
查看Xcode->preferences->key bindings中的comment selection是否设置快捷键
搜索/查看具体快捷键设置
3.Xib界面错乱
进入xib后若界面错乱,则Update Frames更新界面
若继续报错,则删除Xib里的
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
同时修改<document>中的toolsVersion和<plugIn>中的version改成正常的xib文件中的值
4.屏蔽Log
Xcode8新建工程打印时会有许多未见过的Log
屏蔽方法:
Edit Scheme->Run->Arguments->Environment Variables里添加OS_ACTIVITY_MODE = Disable并勾选
5.plist权限修改
若程序崩溃出现privacy-sensitive data警告,则是由于iOS重视安全隐私数据访问导致
- 解决方案
进入info.plist在NSPhotoLibraryUsageDescription键值下进行隐私访问权限设置
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
7.证书
傻瓜式操作,更加易懂,这里不再赘述
8.打印库的加载时长
Edit Scheme->Run->Arguments->Environment Variables里添加DYLD_PRINT_STATISTICS = YES并勾选,可以打印出App加载时长,包括整体加载时长、动态库加载时长
其他问题
1.too many arguments to function call
使用runtime常见,苹果不推荐使用runtime因此默认设为严格检查,解决方法:
Project - Build Settings - ENABLE_STRICT_OBJC_MSGSEND 改为 NO 取消严格审核runtime消息机制
2.Xcode8真机调试报错
- 出现如下错误
dyld: Library not loaded: /System/Library/Frameworks/UserNotifications.framework/UserNotifications
Referenced from: /var/mobile/Applications/BCC39BE7-F54F-460A-963B-9238F3E0DA06/XXX.app/XXX
Reason: image not found
原因:低版本手机中,Xcode高版本Framework不支持
解决方案:
target->Build Phases->Link Binary With Libraries
将UserNotifications.framework的status由Required修改为Optional
- 启动时报错
有全局断点情况设置监控为All,无法找到原因有情况为检测到C++报错,将监控All状态改为Objective-C即可解决