The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

前端 未结 21 1991
醉酒成梦
醉酒成梦 2020-11-22 11:37

I am facing the Problem when I have updated my Xcode to 7.0 or iOS 9.0. Somehow it started giving me the Titled error

\"The resource could not be load

21条回答
  •  天涯浪人
    2020-11-22 12:09

    I managed to solve this with a combination of many of the mentioned options. I’ll include a checklist of all of the things I had to do to get this to work.

    In short:

    1. Set NSAllowsArbitraryLoads to true for my watch extension (not my watch app).
    2. Ensure I was using https and not http.

    Step one:

    Firstly and most obviously I had to add an NSAppTransportSecurity key as a dictionary in my watch extension’s info.plist with a subkey called NSAllowsArbitraryLoads as a boolean set to true. Only set this in the watch extension and not the watch app’s plist. Although take note that this allows all connections and could be insecure.

    or

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
    

    Step two:

    Then I had to make sure that the url I was trying to load was https and not just http. For any urls that were still http I used:

    Swift:

    let newURLString = oldURLString.stringByReplacingOccurrencesOfString("http", withString: "https")

    Obj-C:

    NSString *newURLString = [oldURLString stringByReplacingOccurrencesOfString:@“http” withString:@“https”];

提交回复
热议问题