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;
}

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

你可能感兴趣的:(iPhone,本地推送)