IOS9 那些坑

来源:互联网 发布:程序员等级考试 编辑:程序博客网 时间:2024/06/06 10:43

网络请求

webView 中 调用的NSURL 为 http 时,webView将无法正常显示

因为安全原因 http 无法正常加载,IOS9以上必须使用https (https = http + (安全机制) TSL/SSL)

解决方法:
1. Server https

服务器端更改http为https

2. App 安全机制
打开Info.plist加入以下代码(Source Code)

    <key>NSAppTransportSecurity</key>    <dict>        <key>NSAllowsArbitraryLoads</key>        <true/>    </dict>
NSAppTransportSecurity:  修改当前App的安全机制NSAllowsArbitraryLoads:允许使用以前的非安全的http机制加载

定位功能

IOS9中可以允许一个App使用多个LocationManager, 多个LocationManager可以分类处理,一部分LocationManager前台处理,一部分LocationManager后台处理。

import UIKitimport CoreLocationclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()        let locationManager = CLLocationManager()        locationManager.desiredAccuracy = kCLLocationAccuracyBest        if #available(iOS 9.0, *) {            locationManager.allowsBackgroundLocationUpdates = true        } else {            //#available(iOS 8.0, *)            locationManager.requestAlwaysAuthorization()        }        locationManager.startUpdatingLocation()    }}

以上代码在IOS9中会崩溃,需要加入在info.plist中加入以下代码

<key>NSLocationAlwaysUsageDescription</key>    <string>LocationDemo</string>    <key>UIBackgroundModes</key>    <array>        <string>location</string>    </array>
0 0
原创粉丝点击