Removing iOS permission alert for local notifications when running app in simulator
Asked Answered
M

2

15

I'm trying to write an acceptance test in KIF on an app that asks for local notification permissions pretty early on. Unfortunately due to iOS simulator security reasons it isn't possible to automate accepting iOS permission alerts using KIF. Per https://mcmap.net/q/826528/-ios-permission-alerts-removing-or-suppressing it looks like there are ways to disable the permission alerts for location, address book, calendar, and photos, but I couldn't find a way to disable the local notification permission. I tried the entitlement approach from the linked question but none of the following keys worked:

kTCCServiceNotifications
kTCCServiceNotification
kTCCServiceLocalNotification
kTCCServiceLocalNotifications

Any other ideas? For now I'm working around this by changing my production code to conditionally disable local notifications when acceptance tests are running, but ideally I wouldn't have to.

Mckinnie answered 2/5, 2015 at 22:22 Comment(2)
quick question, where did you find those keys? got a link?Stob
I didn't find those keys, I guessed them, but they don't work. If you look at groups.google.com/forum/#!topic/kif-framework/xayP4VVBPyg you'll see the keys that do work.Mckinnie
S
2

Unfortunately, I don't think in an automation test there is a good way to do this. I know that even resetting the simulator isn't sometimes enough to reset permissions. I would design your tests to not test a system call, but your own application code.

One way to test different functionality based on whether the user allows notifications is to extract the call to check for permissions and then stub this method out in the testing. This method would be the best practice since the goal is not to test if iOS works but if your application code is correct.

Sestina answered 16/7, 2015 at 12:40 Comment(0)
M
0

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
  • navigate to "~/Library/Developer/CoreSimulator/Devices/{$deviceId}/data/Library/BackBoard/applicationState.plist"
  • Replace the applicationState.plist of the UI test simulator with the above one before bootstrapping it
Municipality answered 16/2, 2016 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.