dispatch_async(dispatch_get_main_queue(), ^{
UILocalNotification * localNotification = [[UILocalNotification alloc] init];
if (localNotification)
{
localNotification.fireDate= [[[NSDate alloc] init] dateByAddingTimeInterval:3];
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = @"客户端有新的版本,点击到App Store升级。";
localNotification.alertAction = @"升级";
localNotification.soundName = @"";
[application scheduleLocalNotification:localNotification];
}
});
iOS8中需要在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法下添加如下代码:
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}