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.

解決方法如下:

  1. 開啟專案的  Info.plist
  2. 設定/新增 App Transport Security Settings
  3. 設定/新增 Allow Arbitrary Loads, 設定為 YES
  4. 完成

 

這是因為IOS9後增加了 App Transport Security (ATS) ,詳細請參考說明:

App Transport Security

 

取得網頁內容範例參考

    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");

    }

 

arrow
arrow

    Robarter 發表在 痞客邦 留言(0) 人氣()