สืบเนื่องจากปัญหาเรื่อง bitcode ใน xcode7 จากบทความ ปิด Bitcode ใน Xcode7 หลังจากที่แก้ได้ก็เจอปัญหาเรื่อง Application Transport Security ใน iOS9 ดังนี้เมื่อมีการเรียก API ผ่าน protocal HTTP แล้วได้รับ Error message ตามนี้
“The resource could not be loaded because the App Transport Security policy requires the use of a secure ”
ให่เราเพิ่ม XML เข้าไปใน info.plist ตามนี้ ก็จะสามารถเรียกได้ปกติแล้วครับ กรณีนี้จะทำการอนุญาติ HTTP ทั้งหมด
1 2 3 4 5 |
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> |
หรือถ้าเราจะ อนุญาติเฉพาะ Domain ใด Domain หนึ่งเราก็สามารถทำได้ ดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key> <<Your domain>> </key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> |
Link ด้านล่างเป็น Docs ของ Apple นะครับ
App Transport Security Technote