• ios APNS注册失败 本地push


    - (void)addLocalNotice:(NSString *)titlepush {

    if (@available(iOS 10.0, *)) {

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];

    // 标题

    content.title = titlepush;

    content.subtitle = titlepush;

    // 内容

    content.body = titlepush;

    // 声音

    // 默认声音

    // content.sound = [UNNotificationSound defaultSound];

    // 添加自定义声音

    content.sound = [UNNotificationSound soundNamed:@"Alert_ActivityGoalAttained_Salient_Haptic.caf"];

    // 角标 (我这里测试的角标无效,暂时没找到原因)

    content.badge = @1;

    // 多少秒后发送,可以将固定的日期转化为时间

    NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:10] timeIntervalSinceNow];

    // NSTimeInterval time = 10;

    // repeats,是否重复,如果重复的话时间必须大于60s,要不会报错

    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time repeats:NO];

    /*

    //如果想重复可以使用这个,按日期

    // 周一早上 8:00 上班

    NSDateComponents *components = [[NSDateComponents alloc] init];

    // 注意,weekday默认是从周日开始

    components.weekday = 2;

    components.hour = 8;

    UNCalendarNotificationTrigger *calendarTrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];

    */

    // 添加通知的标识符,可以用于移除,更新等操作

    NSString *identifier = @"noticeId";

    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];

    [center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {

    NSLog(@"成功添加推送");

    }];

    }else {

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

    // 发出推送的日期

    notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

    // 推送的内容

    notif.alertBody = @"你已经10秒没出现了";

    // 可以添加特定信息

    notif.userInfo = @{@"noticeId":@"00001"};

    // 角标

    notif.applicationIconBadgeNumber = 1;

    // 提示音

    notif.soundName = UILocalNotificationDefaultSoundName;

    // 每周循环提醒

    notif.repeatInterval = NSCalendarUnitWeekOfYear;

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];

    }

    }

    NSString *stringInfo=[NSString stringWithFormat:@"APNS error: %@", err];

    [self addLocalNotice:stringInfo];

  • 相关阅读:
    gitlab修改root管理员密码
    【树形 DP】AcWing 325. 计算机
    【图论】AcWing 369. 北大ACM队的远足(DAG 必须边 + 双指针)
    【数据结构】子序列自动机
    前端登录,这一篇就够了(Cookie, Session, Token)
    如何实现一个让面试官惊艳的深克隆
    数据分析前端正则🚀TOP10, 必用⭐正则(77条)
    阿里云ECS安装Archlinux
    golang 哪些类型可以作为map key
    Oracle DG hw重启操作
  • 原文地址:https://www.cnblogs.com/cxcoder/p/10773376.html
Copyright © 2020-2023  润新知