iOS 权限警报 - 删除或抑制

iOS permission Alerts - removing or suppressing

我在 ios 模拟器上有一个简单的应用程序 运行,它将(在应用程序中的某个时刻)提示用户授权以下内容:

  1. 位置设置
  2. 地址通讯录
  3. Pictures/Albums

因为我在iOS模拟器上做自动化测试(在虚拟机上有几千个),有没有办法强制iOS模拟器在应用程序时将这些权限设置为yes安装了吗?

我依稀记得有一种方法可以使用与 iOS 模拟器相关联的 plist 文件来操作它,但我不能 100% 确定是否 "its all in my head"。我在 google.

上找不到太多东西

有一些关于此主题的 discussion here。我会为后代引用相关部分:

For CoreLocation, you can just call the following private method at some point before your first use:

[CLLocationManager setAuthorizationStatus:YES 
                      forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]

Privacy alerts for contacts, photos and the calendar are handled differently. These can be set via TCCAccessSetForBundle from TCC.framework, but this function is not callable from within the same app whose privacy settings you're attempting to modify AFAICT.

Instead, you can just sign your app with these entitlements:

<?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>

To hide your app from the Simulator's Privacy Settings screens, replace com.apple.private.tcc.allow.overridable with com.apple.private.tcc.allow.

You probably don't want to include these entitlements in your AppStore build.

(确保在提交您的应用程序时删除这些内容 - 或者仅将其包含在您的调试目标中 - 因为它不会通过应用程序审核。)

根据上面 Felipe Sabino 的评论,我得出了以下结论。 Xcode 6 的 iOS 权限文件存储在位置:~/Library/Developer/CoreSimulator/Devices/<device>/data/Library/TCC/TCC.db。所以我们在控制台使用sqlite3修改db文件。

从终端使用了以下 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>: \n";  // debug logs
    `sqlite3 /Users/$currentUserID/Library/Developer/CoreSimulator/Devices//data/Library/TCC/TCC.db "insert into access values('kTCCServiceAddressBook','com.apple.store.MyApp', 0, 1, 0, 0)"`;
    print "\n";  // neat logs
}

这个覆盖了 kTCCServiceAddressBook 权限,但还有 kTCCServiceCalendarkTCCServicePhotos