我正在努力audio/video call
并尝试让来电notification
循环 1 分钟,就像 WhatsApp 在iOS
应用程序为背景时显示的那样,Notification banner
隐藏并显示铃声 1 分钟。
我试过这段代码,它只触发一次:
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString stringWithFormat:@"Video Call from %@",userId];
content.body = @"";
content.userInfo = [userInfo mutableCopy];
content.sound = [UNNotificationSound soundNamed:@""];
NSDate *now = [NSDate date];
now = [now dateByAddingTimeInterval:3];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:now];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"INCOMING_VOIP_APN" content:content trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"PUSHKIT : INCOMING_VOIP_APN");
}
}];
我怎样才能做到这一点?我正在使用UserNotifications.framework (iOS 10)
和PushKit
。