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
@DJBen
Copy link

DJBen commented Nov 16, 2015

You might want to add a version that only allows several URLs, but not all.

@myafer
Copy link

myafer commented Jul 25, 2016

`

将如下代码保存为 *.sh 文件

将文件放到 Info.plist 所在目录

修改权限 chmod 777 此文件路径

拉入到命令行回车

第二次之后只需要拉到 Info.plist 所在目录 运行就可以了

#!/bin/bash

project_path=$(pwd)
Info_path=$project_path"/Info.plist"

echo ""
echo ""
echo "没检查属性是否存在,警告不用管"
/usr/libexec/PlistBuddy -c 'Delete :NSAppTransportSecurity' $Info_path
echo "--------------------------------"
echo "即将添加 NSAppTransportSecurity:NSAllowsArbitraryLoads"
/usr/libexec/PlistBuddy -c 'Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool 1' $Info_path
echo "--------------------------------"
echo "添加成功!!!!!!!!!!"
echo ""
echo ""
`

将这句放在 Appdelegate 也可以

: '

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

'

@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