iOS home button warning, is it possible?

2020-02-07 02:08发布

I really don't think this can be done, but still my boss wants me to provide a link where it says so. What he wants is to add an 'are you sure you want to exit?' warning when the user presses the home button, and if the user says 'no' the app won't go inactive. It can't be done, can it?

标签: iphone ios ipad
8条回答
可以哭但决不认输i
2楼-- · 2020-02-07 02:45

The best reference I can find is this one. It's not quite explicit, but Apple's Human Interface Guidelines have a couple of headings 'Always Be Prepared to Stop', followed by 'Don't Quite Programmatically', which spell out what the home button does and that you shouldn't be implementing your own quitting strategies.

查看更多
叼着烟拽天下
3楼-- · 2020-02-07 02:46

No, you cannot do this - the application has no say in this. Ask your boss whether he has ever seen a single example of an iOS application that would do this. There isn't ... not one I would bet.

The application can continue to execute some functionality in the background - streaming music, getting location information for example, but no application can block the home button. If you could do this, you could block an application from ever closing.

A) You couldn't technically do this and

B) Apple wouldn't allow it to be released on the App Store if that was the distribution route you were taking

If you look at the methods stubs created by XCode when you create an application delegate

-(void)applicationWillResignActive:(UIApplication *)application

-(void)applicationWillTerminate:(UIApplication *)application

That are filled will comments about how you can use this method to pause tasks, disable timers, throttle down frame rates, save data - there is nothing about being able to delay, query the user with an "Are you sure" message.

This whole idea is rather counter to the user-experience of the iPhone/Pad/Pod-Touch.

From the App Store guidelines (slightly abbreviated):

Apps that alter the behavior of switches on the device will be rejected

This is a proposed change the behavior of the home button - so would be rejected.

查看更多
走好不送
4楼-- · 2020-02-07 02:47

This is possible on a jail broken device, using un-aproved API's. The concept is in multiple violations of apple's usage policy however so you would never, ever, ever get an app attempting to implement this in any way on the official app store. Here's just a few reasons:

  1. You can't alter the functionality of any buttons (including the volume buttons, some camera apps used to use them to take pictures, but they got booted from the store as a result).
  2. You can't interfere with standard user interactions with the device. The home button takes people home, you can't prevent that, or ask for confirmation as that would be interfering with the interaction.
  3. There is no public API to detect actual usage of the home button. As such you would need a private API, and you can not use private API's without explicit permission from Apple, which they would never give due to #1 and #2 above.

I'm sure there's plenty of more reasons, but regardless it would be in direct violation of app store policies as well as iOS human interface guidelines.

You can detect when the app is about to lose focus, has lost focus, or could loose focus (such as a phone call is coming in) but you can not alter the flow (i.e. not allow the app to lose focus).

You can continue to execute code in the background within the backgrounding guidelines and limitations. The backgrounded code could submit a notification to the user that would allow them to switch back into the app... that's about as close as you could get, and expect apple to reject you if it happens every time the app closes...

查看更多
闹够了就滚
5楼-- · 2020-02-07 02:52

Already answered by numerous others, but no, you can't do this. When the user presses the home button, your application delegate's applicationWillResignActive is called which disables touch events to the application. Then applicationDidEnterBackground is called, which, per the Apple docs:

Your delegate’s applicationDidEnterBackground: method has approximately 5 seconds to finish any tasks and return. In practice, this method should return as quickly as possible. If the method does not return before time runs out, your application is killed and purged from memory

查看更多
一纸荒年 Trace。
6楼-- · 2020-02-07 02:52

You need proof to show your boss that obviously isn't an iOS developer.

Apple Human Interface Guide

That should be all the proof you need. But to be clear, Apple will not allow an app to override the home button in any way. You can surely put action sheets or pop ups to warn before logging out, but once the home button is pressed, you are on notice to give up your memory, you are being shut down.

查看更多
对你真心纯属浪费
7楼-- · 2020-02-07 02:54

You might want to look into the Store Demo Mode of IOS. This way you can disbale the Home button and lock the device in the first app you start after booting.

查看更多
登录 后发表回答