首页 > 其他 > 详细

推送通知--本地推送通知

时间:2015-10-20 19:47:42      阅读:278      评论:0      收藏:0      [点我收藏+]

@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

   

    //1.创建本地通知的对象

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

    

    //2.设置通知触发的时间

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    

    //3.设置弹出提示的内容

    notification.alertBody = @"吃饭啦啦啦啦";

    

    //4.设置按钮的标题

    notification.alertAction = @"提醒";

    

    

    //注册本地通知,注册之后,通知才会生效

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

    

    //设置消息提醒的数目

    [UIApplication sharedApplication].applicationIconBadgeNumber = 3;

}

//UIAppDelegate中设置



@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

   

    //iOS8以后需要设置以下代码

    UIUserNotificationType type = UIUserNotificationTypeBadge |UIUserNotificationTypeAlert | UIUserNotificationTypeSound;

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    return YES;

}


- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

{

    NSLog(@"lalalala");

    application.applicationIconBadgeNumber = 0;

}


推送通知--本地推送通知

原文:http://10594302.blog.51cto.com/10584302/1704486

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!