Skip to content

Instantly share code, notes, and snippets.

@onevcat
Last active January 12, 2018 12:32
Show Gist options
  • Save onevcat/b4604aecb4ce55651a4a to your computer and use it in GitHub Desktop.
Save onevcat/b4604aecb4ce55651a4a to your computer and use it in GitHub Desktop.
Fuck off ATS
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
/usr/libexec/PlistBuddy -c "Add:NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" ./Info.plist
@monkey19911021
Copy link

monkey19911021 commented Aug 12, 2016

写一个 AppleScript 脚本文件:

set plistPath to POSIX path of (choose file of type {"plist"})
tell application "Terminal"
    reopen
    activate
    do script ("/usr/libexec/PlistBuddy -c 'Delete :NSAppTransportSecurity' " & plistPath) in window 1
    do script "echo --------------------------------" in window 1
    do script "echo 即将添加 NSAppTransportSecurity:NSAllowsArbitraryLoads" in window 1
    do script ("/usr/libexec/PlistBuddy -c 'Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool 1' " & plistPath) in window 1
    do script "echo --------------------------------" in window 1
    do script "echo 添加成功!!!!!!!!!!" in window 1
end tell

运行起来只需要选择目标 Info.plist 文件就可以写入数据了。

@github641
Copy link

github641 commented Nov 24, 2016

使用 Plistbuddy 是否先delete 存在键值比较好,因为存在时add是不行的,需要Set;而且有时手动删除后add,依然报“xxx键已经存在”。

放在AppDelegate中的方法试验没有效果,是使用不正确还是什么问题呢?
@myafer
NSString *str = [NSString stringWithFormat:@"%s", __FILE__]; NSArray *pp = [str componentsSeparatedByString:@"/"]; NSMutableString *mu = [NSMutableString string]; for (int i = 1; i < pp.count - 1; i ++) { [mu appendString:[NSString stringWithFormat:@"/%@", pp[i]]]; } [mu appendString:@"/Info.plist"]; NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:mu]; [data setObject:@{@"NSAllowsArbitraryLoads":@(1)} forKey:@"NSAppTransportSecurity"]; [data writeToFile:mu atomically:YES]; NSLog(@"%@", mu);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment