在模拟器中运行应用程序时删除本地通知的iOS权限警报 [英] Removing iOS permission alert for local notifications when running app in simulator

查看:209
本文介绍了在模拟器中运行应用程序时删除本地通知的iOS权限警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 KIF 上针对要求的应用编写验收测试很早就有本地通知权限。不幸的是,由于iOS模拟器的安全原因,使用KIF无法自动接受iOS权限警报。根据 https://stackoverflow.com/a/28443743/62 ,有些方法可以禁用权限警报位置,地址簿,日历和照片,但我找不到禁用本地通知权限的方法。我尝试了链接问题的权利方法,但没有以下密钥工作:

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.

推荐答案

不幸的是,我认为在自动化测试中没有一种很好的方法可以做到这一点。我知道即使重置模拟器有时也不足以重置权限。我会将您的测试设计为不测试系统调用,而是测试您自己的应用程序代码。

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.

根据用户是否允许通知来测试不同功能的一种方法是提取调用以检查权限,然后在测试中将此方法存根。这种方法是最好的做法,因为目标不是测试iOS是否有效但是你的应用程序代码是否正确。

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.

这篇关于在模拟器中运行应用程序时删除本地通知的iOS权限警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆