您的位置:首页 > 移动开发 > IOS开发

iOS本地通知(iOS8改变)

2015-01-29 10:34 465 查看
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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: