Problem with applicationShouldTerminate on iPhone

后端 未结 4 1374
再見小時候
再見小時候 2021-01-24 05:57

I\'m having a problem with applicationShouldTerminate.

What ever I do it seams that has no effect. Any help would be appreciated.

I\'m well versed in programing

相关标签:
4条回答
  • 2021-01-24 06:21

    I know this is a non-answer, but hopefully I can be helpful:

    Displaying a "Really quit?"-type alert like this, even if you can pull it off technically (and I'm not sure you can), is a bad idea and is likely to either cause rejection from the App Store or, at best, an inconsistent user experience because no other apps do this.

    The convention with iPhone apps is to save state if necessary, then yield control (for termination) as quickly as possible when the user hits the home button or switches apps.

    To ensure a consistent experience, Apple probably has an aggressive timer in place to restrict what you can do in applicationWillTerminate. And even if they don't have a technical measure in place, they probably have an App Store approval policy to ensure that applications quit immediately when they're asked to.

    0 讨论(0)
  • 2021-01-24 06:27
    1. applicationShouldTerminate and NSApplication do not exist on the iPhone. You have to use UIApplication.

    2. The alert view is never shown because the 'show' method does not block, and therefore, the end of 'applicationWillTerminate' is reached immediately after you create the alert view and try to show it. I believe this is by design. You can't really begin asynchronous operations in 'applicationWillTerminate'.

    0 讨论(0)
  • 2021-01-24 06:35

    With regards to the applicationShouldTerminate error, in case anyone's curious, NSApplicationTerminateReply and NSApplication seem to be deprecated...even though the OP's method is exactly how it appears in the docs!

    Defining your method as the below should build with no errors:

    -(BOOL)applicationShouldTerminate :(UIApplication *)application
    
    0 讨论(0)
  • 2021-01-24 06:35

    I think I found the answer to what I wanted to do but will need to check it when I get back home. Some directions were found here

    http://blog.minus-zero.org/

    The iPhone 2.0 software was recently released, and with it came the ability for users to download native apps (i.e., not web sites) directly to their phones from within the iPhone UI or via iTunes. Developers (anyone who pays Apple 59GBP for the privilege) can then write their own apps and have them available for purchase in the App Store.

    One limitation of the Apple-sanctioned SDK is that only one application is allowed to be running at a time. This presents a problem for apps such as IM clients, music players and other programs whose functionality relies on being able to run in the background. Another example (courtesy of James) would be an app that takes advantage of the iPhone 3G's GPS chip to create a log of all the places you visit.

    However, there is a neat trick that I discovered: your app will only get terminated if you switch away from it, and hitting the iPhone's power button while your app is in the foreground doesn't count as switching away. The upshot of this is you can create apps which continue to run while the iPhone is in your pocket - perfect for the GPS example.

    Achieving this is as simple as implementing two methods in your UIApplication delegate - applicationWillResignActive: and applicationDidBecomeActive:. Here's a simple example to demonstrate the effect.

    In your UIApplication delegate header file, add a new ivar: BOOL activeApp. Then, in your implementation, add the following three methods:

    - (void)applicationWillResignActive:(UIApplication *)application {
      NSLog(@"resigning active status...");
      activeApp = NO;
      [self performSelector:@selector(sayHello) withObject:nil afterDelay:1.0];
    }
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
      NSLog(@"becoming the active app...");
      activeApp = YES;
    }
    
    - (void)sayHello {
      NSLog(@"Hello!");
      if (!activeApp)
        [self performSelector:@selector(sayHello) withObject:nil afterDelay:1.0];
    }
    
    0 讨论(0)
提交回复
热议问题