Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS permission Alerts - removing or suppressing

I have a simple app running on ios simulator which will (at some point in the app), prompt the user to authorize the following:

  1. Location setting
  2. Address contact book
  3. Pictures/Albums

Because I am doing automation testing on the iOS simulator (several thousand on virtual machines), is there a way to force iOS simulator to have these permissions already set to yes when the app is installed?

I vaguely remember there was a way to manipulate this using a plist file associated with iOS simulator, but I'm not 100% sure if "its all in my head". I'm not finding much on google.

like image 524
Just a coder Avatar asked Feb 10 '15 23:02

Just a coder


People also ask

How do I stop IOS permission alerts?

Notification permission can be suppressed by granting permission in applicationState. plist: Run your app on a simulator and tap on "ok" for any permission popups.

What is IOS alert?

Your iPhone will alert you when there's a message, voicemail, email or other updates. Your iPhone can alert you with a sound, or a text alert on your screen. There are different alert styles notifications, banners, and badges. You can also choose to not have any type of alerts on your iPhone by modifying settings.

Where do I find Alerts on my iPhone?

Find your notifications in Notification Center On the Lock Screen: Swipe up from the middle of the screen. On other screens: Swipe down from the top center. Then you can scroll up to see older notifications, if there are any.


2 Answers

Based on the comment by Felipe Sabino above I worked out the following. The permissions file of iOS for Xcode 6 is stored at location: ~/Library/Developer/CoreSimulator/Devices/<device>/data/Library/TCC/TCC.db. So we modify the db file using sqlite3 on the console.

Used the following Perl script from terminal. This could be done in any language really.

$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
}

This one overrides kTCCServiceAddressBook permission, but there is also kTCCServiceCalendar and kTCCServicePhotos.

like image 120
Just a coder Avatar answered Oct 01 '22 02:10

Just a coder


There's some discussion here on this topic. I'll quote the relevant portion for posterity:

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.

(Make sure to take this stuff out when you submit your app - or only include it in your debug target - because it won't pass app review.)

like image 30
Aaron Brager Avatar answered Oct 01 '22 04:10

Aaron Brager