iOS 本地通知 做会议闹钟用

最近在公司做一个功能 做一个日历 并且集成outlook 根据响应的日程时间显示出邮箱的数据,并且邮箱里面有会议时 ,像闹钟一样提醒用户.以前也没做过相应的功能,感觉压力山大,日历因为项目时间紧,所以找了个第三方的改造一下来适应项目的需求.基本搞定,对于日程的提醒还是第一次接触,在网上搜了许多资料,不是方法太老,就是收不到提醒,最后看了文档添加了一个方法就能收到本地的通知.

if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }

完整代码

#pragma mark initView
-(void)initView{
    
    if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    NSInteger period = 10.0;
    UILocalNotification *notification=[[UILocalNotification alloc] init];
    if(notification!=nil){
        NSDate *now = [NSDate date];
        notification.fireDate = [now dateByAddingTimeInterval:period];
        notification.repeatInterval = 0;//循环次数
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.alertBody = @"该去打豆豆了";
        notification.alertAction =NSLocalizedString(@"ddddd", nil);
        notification.hasAction = YES;
                NSDictionary* infoDic = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
        notification.userInfo = infoDic;
        
        //发送通知
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        
    }
}



有点略坑啊 在网上的许多代码 本地通知都没有这段代码  导致 在模拟器上运行没有收到本地通知 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值