我的應用程序擴展需要打開許多網站的URL。我做如下:Safari擴展應用程序傳輸安全
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
NSLog(@"URL: %@",url);
我能得到的URL,但在這一點上,我得到這個錯誤:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
我想徹底關閉ATS,
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key> <true/>
</dict>
但它不起作用,並且我無法在NSExceptionDomain中列出網站。我嘗試在模擬器和設備上。有人可以幫忙嗎?
編輯
我認爲,這會導致問題的代碼是這樣的:
NSString* htmlString = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding]
我使用這行代碼URL日誌後才能獲取HTML爲純文本。
感謝您的回答,但它對我無效。在plist中的值設置爲YES,並且我嘗試了您的方法來獲取html,但它返回給我 – Totka
@Totka我假設您已經在ios8中嘗試了此URL並且它可以正常工作。我發現有時在http上添加一個「s」使它可以在ios9上運行。 –