美文网首页
ios发送本地通知

ios发送本地通知

作者: zhhehj | 来源:发表于2019-11-22 14:26 被阅读0次
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center requestAuthorizationWithOptions:UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if(granted) {
                UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
        UNNotificationSound* sound = [UNNotificationSound soundNamed:self.voiceArray[0]];
        content.sound = sound;
        UNTimeIntervalNotificationTrigger* tirgger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1
                   repeats:NO];
        UNNotificationRequest* rt = [UNNotificationRequest requestWithIdentifier:@"notificationKey" content:content trigger:tirgger];
    
        [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:rt
                   withCompletionHandler:^(NSError* _Nullable error) {
            NSLog(@"%@本地推送 :(%@", @"notificationKey", error);
            if (self.voiceArray.count > 0) {
                [self.voiceArray removeObjectAtIndex:0];
                [self setLocalNotification];
            }
            else {
                self.contentHandler(self.bestAttemptContent);
            }
        }            
        }];
    }];

    相关文章

      网友评论

          本文标题:ios发送本地通知

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