英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论