I want to have a local notification show up as soon as the application is downloaded off the app store and is opened. Thanks.

有帮助吗?

解决方案

You can do that in your app delegate's didFinishLaunchingWithOptions. You need to do the following in this method:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    ....
    //Get the version number of the application using this technique: http://stackoverflow.com/questions/458632/how-can-my-iphone-app-detect-its-own-version-number
    NSString version = [self appVersion];
    //Because you only want to display the notification on first launch so have a flag in user defaults to track that. Also note that you need to include this in your registerDefaults and set to NO
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    BOOL alreadyDisplayedNotification = [defaults boolForKey:@"alreadyDisplayedNotificationOnStartForVersion"];
    if ([version isEqualToString:@"VersionForWhichYouWantNotification"] && !alreadyDisplayedNotification) {
        //Display Notification...

        // Set the flag in user default to track that notification has been displayed
        [defaults setBool:YES forKey:@"alreadyDisplayedNotificationOnStartForVersion"]; 
    }
    .....
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top