在Swift中,如何在按钮点击时终止iOS应用程序。

huangapple go评论66阅读模式
英文:

How to terminate iOS app on button tap in Swift

问题

我需要在没有网络连接的情况下打开我的应用程序时,在Swift中实施一个方案。然后,我必须在MainScreen上显示一个警告,以通知用户,并提供一个名为“Deny”的警告按钮。因此,如果用户选择拒绝启用移动数据,应用程序应该被终止。

您知道实现这一功能的正确方法是什么,以便苹果在此实施后接受我的应用程序进入App Store吗?我看到之前与此主题相关的帖子,其中建议使用exit(0),但苹果似乎强烈反对这样做。

英文:

I have a scenario to implement in Swift when there is no internet connection and user opens my app. Then, I have to show an alert on MainScreen to inform user with an alert button called "Deny". So, if user choose to deny to enable mobile data, the app should be terminated.

Do you know what's the proper way to implement this feature that Apple will accept my app on App Store after this implementation? I saw previous posts related to this topic where the recommendation is exit(0) but Apple seems to strongly discourage it.

答案1

得分: 1

检查设备在着陆页面上是否连接到互联网,使用Reachability库。如果由于控制结果未连接到互联网,不应进入其他屏幕并发出警告。强制关闭应用程序会不好。

英文:

Check if the device is connected to the Internet using the Reachability library on the landing page. If it is not connected to the internet as a result of the control, it should not go to the other screen and give a warning. It would be bad to force close the app.

huangapple
  • 本文由 发表于 2023年7月18日 16:33:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定