如何显示警报时,应用程序在IOS

问题描述:

当我的应用程序在前台运行被关闭,如果用户点击主页按钮我想告诉喜欢如何显示警报时,应用程序在IOS

一些警告不要ü想退出该应用程序是/没有按钮。是否有任何代表方法被称为当主页按钮被点击时...

谢谢...。

+1

不,你不能这样做,在iOS中。有一个代表通知,但您的应用程序将立即转到后台。 – KudoCC

+0

无论如何,你绝对不应该这样做。如果用户点击主页按钮,他们想要离开您的应用程序。您的业​​务无一为何,而且您无权干涉用户的行为。除非你想要1星评价(假设0星是不可能的)。 – gnasher729

+0

请花一点时间接受答案(点击复选标记)。你也可以投票的答案,因为有几个人试图帮助你:) – 2015-08-29 06:39:53

在iOS上没有办法做到这一点。我想你想要一个类似于Android后退按钮的行为。

将iOS主页按钮想象成Android主页按钮,它不会让您提示用户。

+1

是的,我想要类似的行为,如android,我也搜索了它没有发现任何信息,感谢您的确认.. –

即使您显示警告消息,您也无法停止应用程序以进入后台,无论如何,当您点击主屏幕按钮时,您都不会看到警报消息。

没有委托方法会在应用程序转到后台时触发,但是有一个委托方法会在应用程序完全转到后台时触发。

只是为了告诉你visually-

在AppDelegate中实现文件(.M),我在applicationDidEnterBackground方法的末尾添加一条警告消息,并把一个破发点只是为了检查其是否进入该块作为我期望。见result--

enter image description here

可以在使用这些方法AppDelegate.m

- (void)applicationDidEnterBackground:(UIApplication *)application { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 


} 

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
} 
+0

这将不会帮助显示消息。 applicationDidEnterBackground方法将在应用完全转到后台后触发,而不是在单击主页按钮时触发。 – Natasha

+0

你有什么建议然后 –

+0

我已经提供了一个建议。事情是,在iOS中,当用户点击主页按钮时,您无法控制任何内容。无论如何,该应用程序将转到后台。我们不能停止这个过程。至少,我没有找到任何解决方案。 – Natasha