close
使用IOS要送出網頁請求,卻一直收到NULL,後來攔截到ERROR CODE 是-1022
錯誤訊息為The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
解決方法如下:
- 開啟專案的 Info.plist
- 設定/新增 App Transport Security Settings
- 設定/新增 Allow Arbitrary Loads, 設定為 YES
- 完成
這是因為IOS9後增加了 App Transport Security (ATS) ,詳細請參考說明:
取得網頁內容範例參考
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"http://google.com"]]; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if(conn) { NSLog(@"Connection Successful"); } else { NSLog(@"Connection could not be made"); } |
文章標籤
全站熱搜