0

我希望在应用程序从应用商店下载并打开后立即显示本地通知。谢谢。

4

1 回答 1

0

您可以在应用程序委托的 didFinishLaunchingWithOptions 中执行此操作。您需要在此方法中执行以下操作:

- (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"]; 
    }
    .....
}
于 2013-06-27T14:34:54.190 回答