UILocalNotification本地通知

 

 

// 执行通知一定要退出应用或挂起应用(进入后台)才能收到通知。

// 创建本地通知

UILocalNotification *notification = [[UILocalNotification alloc] init];

// 通知触发时间

// 5秒钟之后触发
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

// 通知时区

// 使用本地时区
notification.timeZone = [NSTimeZone defaultTimeZone];

// 通知提示内容

notification.alertBody = @"顶部提示内容,您有有一个通知";

// 通知提示音

//使用默认的通知提示音
notification.soundName = UILocalNotificationDefaultSoundName;

// 应用程序右上角显示的数字

notification.applicationIconBadgeNumber = 1;

// 数据字典

notification.userInfo = @{@"userName": @"小明", @"age": @(18)};

// 启动这个通知

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

// 进入前台,清除右上角图标

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [application setApplicationIconBadgeNumber:0];
}

// 点顶端通知进入应用

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:notification.userInfo[@"userName"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

 // 清除当前应用所有通知

[[UIApplication sharedApplication] cancelAllLocalNotifications];

转载于:https://www.cnblogs.com/android-dev/p/3794072.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值