iOS权限警报 – 删除或surpressing
我有一个简单的应用程序在ios模拟器上运行,将(在应用程序的某个时刻),提示用户授权以下内容:
- 位置设置
- 地址通讯簿
- 图片/相册
因为我在iOS模拟器上进行自动化testing(在虚拟机上有数千个),有没有办法强制iOS模拟器在安装应用程序时将这些权限设置为yes?
我隐约记得有一种方法来操纵这个使用与iOS模拟器相关的plist文件,但我不是100%确定“它的全部在我脑海中”。 我在谷歌上找不到很多东西。 我将不胜感激任何帮助。
这里有一些关于这个话题的讨论。 我会引用后人的相关部分:
对于CoreLocation,您可以在首次使用之前的某个时刻调用以下私有方法:
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]
联系人,照片和日历的隐私警报处理方式不同。 这些可以通过
TCCAccessSetForBundle
的TCC.framework
来设置,但是这个函数不能从你试图修改AFAICT的隐私设置的应用程序中调用。相反,您可以使用这些权利在您的应用程序上签名:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.private.tcc.allow.overridable</key> <array> <string>kTCCServiceAddressBook</string> <string>kTCCServiceCalendar</string> <string>kTCCServicePhotos</string> </array> </dict> </plist>
要从模拟器的隐私设置屏幕上隐藏您的应用程序,请使用
com.apple.private.tcc.allow.overridable
replacecom.apple.private.tcc.allow
。您可能不希望在AppStore构build中包含这些权利。
(确保在提交应用程序时把这些东西拿出来 – 或者只把它包含在debugging目标中 – 因为它不会通过应用程序审查。)
根据上面的Felipe Sabino的评论,我制定了以下内容。 适用于XCode 6的iOS权限文件存储在以下位置: ~/Library/Developer/CoreSimulator/Devices/<device>/data/Library/TCC/TCC.db
。 所以我们在控制台上使用sqlite3修改数据库文件。
从terminal使用以下Perl脚本。 这可以用任何语言来完成。
$folderLocations = `xcrun simctl list`; // running "xcrun simctl list" on terminal returns iOS device locations $currentUserID = `id -un`; // get current user chomp($currentUserID); // remove extra white space from user string print "currentUserID: $currentUserID"; // debug logs while($folderLocations =~ /iPad Air \((.{8}-.*?)\)/g) { // Use regex to loop through each iPad Air device found in $folderLocations. Insert the permissions in the database of each. print "folderLocations <1>: $1\n"; // debug logs `sqlite3 /Users/$currentUserID/Library/Developer/CoreSimulator/Devices/$1/data/Library/TCC/TCC.db "insert into access values('kTCCServiceAddressBook','com.apple.store.MyApp', 0, 1, 0, 0)"`; print "\n"; // neat logs }
这个覆盖kTCCServiceAddressBook
权限,但也有kTCCServiceCalendar
和kTCCServicePhotos
。