美文网首页
本地推送

本地推送

作者: 5a9c6f44e578 | 来源:发表于2018-11-26 11:22 被阅读7次
      if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
            
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
            
        if (UIUserNotificationTypeNone == setting.types) {
                
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"请允许使用推送功能,以便预约直播后提醒您观看名医直播" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往修改", nil];
             [alert show];
                
            }  else  {   // 推送打开
                
        // 设置通知的类型可以为弹窗提示,声音提示,应用图标数字提示
        UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
                // 授权通知
                [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
      NSLog(@"111111   %@",self.liveModel.vname);
        NSLog(@"222222   %@",self.liveModel.descr);
                
                
        [MBProgressHUD showAutoMessage:@"预约成功"];
                
        // 1.创建通知
        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
                // 2.设置通知的必选参数
                // 设置通知显示的内容
        localNotification.alertBody = self.liveModel.descr;
                // 设置通知的发送时间
        localNotification.fireDate = [NSDate dateWithTimeIntervalSince1970:1543205206000/ 1000];
        localNotification.alertTitle = self.liveModel.vname;
                
                localNotification.applicationIconBadgeNumber = 1;
                localNotification.soundName = UILocalNotificationDefaultSoundName;
                // 3.发送通知
                // 方式一: 根据通知的发送时间(fireDate)发送通知
                [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
                
                // 方式二: 立即发送通知
                //    [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
            }
        }
        ````
    

    相关文章

      网友评论

          本文标题:本地推送

          本文链接:https://www.haomeiwen.com/subject/klovqqtx.html