【发布时间】:2017-01-25 07:16:58
【问题描述】:
我正在处理 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。
【问题讨论】:
-
@Jayprakash Dubey:你能帮忙解决这个问题吗?
-
您希望在此处收到连续 1 分钟或 1 分钟间隔的通知?
-
我希望通知显示 3 秒并隐藏,这个过程应该只运行 1 分钟,就像应用程序在 ios 中处于后台时的 whatsapp 来电一样
-
@AbhishekThapliyal 我面临同样的问题,你能帮我解决这个问题吗?
-
@siva krishna : 使用带有过期处理程序的后台任务raywenderlich.com/29948/backgrounding-for-ios 在同一线程中显示带有计时器的本地通知 1 分钟播放音频 请也支持我的问题 :)
标签: ios objective-c notifications voip usernotifications