应用程序下载时的本地通知

时间:2013-06-27 13:37:36

标签: xcode localnotification

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

1 个答案:

答案 0 :(得分:0)

您可以在app delegate的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"]; 
    }
    .....
}