Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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://stackoverflow.com/a/28443743/62 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.

like image 215
Liron Yahdav Avatar asked May 02 '15 22:05

Liron Yahdav


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.

Does notification work on simulator?

If your target platform is Android, you can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications.

Do notifications work on iOS simulator?

Yes, that's true. I always wondered if I can send a Push Notification on iOS simulator instead getting a real device while developing applications. Simulator supports simulating remote push notifications, including background content fetch notifications.

How do I enable push notifications on Iphone simulator?

“Simulator supports simulating remote push notifications, including background content fetch notifications. In Simulator, drag and drop an APNs file onto the target simulator. The file must be a JSON file with a valid Apple Push Notification Service payload, including the “aps” key.


1 Answers

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.

like image 183
Christian Di Lorenzo Avatar answered Oct 05 '22 10:10

Christian Di Lorenzo