iOS学习笔记31-本地通知

创建并调用本地通知的几个步骤

1,创建本地通知

2,设置处理时间

3,设置通知主体

4,可以设置传递的参数userinfo

5,调用通知

 

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

    

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];

    

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:23/255.0 green:180/255.0 blue:237/255.0 alpha:1]];

    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];

    

    ViewController *viewController = [[ViewController alloc]init];

    self.window.rootViewController = viewController;

    

    [self.window makeKeyAndVisible];

    

    

    

    if ([[UIApplication sharedApplication]currentUserNotificationSettings].types != UIUserNotificationTypeNone) {

        [self addLocalNotification];

    }else{

        [[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound  categories:nil]];

    

    

    

    }

    // Override point for customization after application launch.

    return YES;

}

 

 

 

 

 

 

 

 

 

 

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings

{

    if (notificationSettings != UIUserNotificationTypeNone) {

        [self addLocalNotification];

    }

 

 

}

 

 

 

 

 

 

-(void)addLocalNotification{

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

    

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2.0];

    notification.repeatInterval = 2;

    

    notification.alertBody = @"该睡觉了哦!~~";

    notification.applicationIconBadgeNumber = 2;

    notification.alertAction = @"打开应用";

    

    notification.alertLaunchImage = @"Default";

    notification.soundName = @"msg.caf";

 

    notification.userInfo = @{@"id":@1,@"name":@"dsn"};

    [[UIApplication sharedApplication]scheduleLocalNotification:notification];

 

}

 

 

 

- (void)applicationWillEnterForeground:(UIApplication *)application {

    

    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];

    

    

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

 

转载于:https://www.cnblogs.com/adodo/p/5226245.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值