来电时一分钟如何显示通知栏?

时间:2019-10-29 11:37:32

标签: ios objective-c push-notification nsusernotification notification-bar

我尝试了多种方法在1分钟的时间范围内显示通知横幅,但在3秒内将其关闭。如果有人知道该解决方案,请提供帮助。

UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString stringWithFormat:@"Video Call from %@",@"siva"];
content.body = @"";
//   content.userInfo = [userInfo mutableCopy];
content.sound = [UNNotificationSound defaultSound];

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];

UNTimeIntervalNotificationTrigger *trigger=[UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:YES];


 // UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
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");
    }
}];

0 个答案:

没有答案