Ionic在ios10下白屏的解决方案

在IOS10上运行项目的时候,跳过闪屏图页面后,就不断的加载,无法进入页面。而且貌似日志里没有什么参考的信息可供参考

后来在github上翻阅到同样的issue

https://github.com/driftyco/ionic/issues/6928

原来是gap://ready 导致的csp问题,别人的日志里的提示:

[Error] Refused to load gap://ready because it appears in neither the child-src directive nor the default-src directive of the Content Security Policy.
[Error] Refused to connect to file:///var/containers/Bundle/Application/<…>/Compass.app/www/templates/login.html because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy. (x6)

解决办法,就是在你index.html 添加gap: 的csp配置

 

IOS10下网络请求异常

本以为《微打卡》在ios9下跑的没问题就提交上去了,结果当天就被打回,原因告知是在ios10测试出现bug

于是在xcode8下运行iphone7的模拟器,在日志里看到了下面的信息

2016-09-30 09:44:30.460983 微打卡[21322:1592668] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
[x86_64] libnetcore-856.1.8
0 libsystem_network.dylib 0x000000010badf80e __nw_create_backtrace_string + 123
1 libnetwork.dylib 0x000000010c6e4194 nw_socket_add_input_handler + 3002
2 libnetwork.dylib 0x000000010c6c1db8 nw_endpoint_flow_attach_protocols + 3768
3 libnetwork.dylib 0x000000010c6c0dd5 nw_endpoint_flow_setup_socket + 563
4 libnetwork.dylib 0x000000010c6bfb34 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
5 libnetwork.dylib 0x000000010c6dad11 nw_endpoint_handler_path_change + 1261
6 libnetwork.dylib 0x000000010c6da740 nw_endpoint_handler_start + 570
7 libnetwork.dylib 0x000000010c6f2003 nw_endpoint_resolver_start_next_child + 2240
8 libdispatch.dylib 0x000000

解决方法就是

在xcode,进入菜单product-scheme-edit scheme 添加环境变量OS_ACTIVITY_MODE 为 disable 即可,如下图


但是,日志里貌似还有一个错误提示

objc[23023]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x110589910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11031c210). One of the two will be used. Which one is undefined.

初步判断是2个库冲突,但是解决方法未知。

IOS10下的用户隐私访问问题

最近提交《微打卡》到AppStore下的时候,出现以下提示:
We have discovered one or more issues with your recent delivery for “微打卡”. To process your delivery, the following issues must be corrected:

This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSBluetoothPeripheralUsageDescription key with a string value explaining to the user how the app uses this data.

This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

出现这个问题是因为iOS对用户的安全和隐私的增强,在申请很多私有权限的时候都需要添加描述,但是,在使用Xcode 8之前的Xcode还是使用系统的权限通知框.要想解决这个问题,只需要在info.plist添加NSContactsUsageDescription的key, value自己随意填写就可以,例如:

如果不起作用,可以请求后台权限,类似于这样:

或者在Xcode里选中当前的target,选择Capabilities,找到Background Modes,打开它,在里面选择对应权限.

IOS10下的ATS问题

最近IOS10更新之后,我的《微打卡》APP在调用微博API接口的时候,一直失败,提示以下错误:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

大部分的开发者都知道从IOS9以后,apple默认禁止非https的网络访问,所以我们的通用做法是在info.plist里增加

但是最新的wwdc的会上,苹果又放出新规:

从2017年1月1日起,,所有新提交的 app 默认不允许使用NSAllowsArbitraryLoads
来绕过ATS的限制,默认情况下你的 app 可以访问加密足够强的(TLS V1.2以上)HTTPS内容;

针对这个问题,我们可以使用NSExceptionDomains对特定域名开放http请求
,比如第三方微博登录,我们可以进行如下配置:

不过,如果有条件还是建议将你的网站升级到https,毕竟这也是未来的趋势。