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

一世执手 提交于 2019-12-31 20:07:29

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/30008145/removing-ios-permission-alert-for-local-notifications-when-running-app-in-simula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!