IOS 本地推送消息以及进入后台继续推送

首先编写本地推送的代码

UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:10];
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.applicationIconBadgeNumber = 1; //设置右上角小圆圈数字为1
        notification.soundName= UILocalNotificationDefaultSoundName;
        notification.alertBody = @“推送测试”;
        [[UIApplication sharedApplication]  scheduleLocalNotification:notification];


当按下Home健,程序开始进入后台,那么如果还要接受的话,需要在AppDelegate中加入如下代码。

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
        NSLog(@" application Recieved Notification %@",notif);
    app.applicationIconBadgeNumber = 0;
}

那么即使设备在锁定状态下,仍然能够显示本地推送。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值