下载应用程序时的本地通知
Posted
技术标签:
【中文标题】下载应用程序时的本地通知【英文标题】:Local Notification When App is Downloaded 【发布时间】:2013-06-27 13:37:35 【问题描述】:我希望在应用程序从应用商店下载并打开后立即显示本地通知。谢谢。
【问题讨论】:
您是否也希望在应用程序升级到新版本后首次启动时收到此通知? 不,仅适用于我当前的更新。 【参考方案1】:您可以在应用代理的 didFinishLaunchingWithOptions 中执行此操作。在这个方法中你需要做以下事情:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
....
//Get the version number of the application using this technique: http://***.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"];
.....
【讨论】:
以上是关于下载应用程序时的本地通知的主要内容,如果未能解决你的问题,请参考以下文章