我的标题可能无法准确描述我的问题,所以我很抱歉。我一直在寻找创建此级别功能的解决方案,但我无法找到它。
我正在为 iOS 8 创建 VoIP 应用程序。当用户接到电话时,我将显示一条带有 12 秒铃声的通知。当此通知正在进行时,如果呼叫断开,我希望来电通知消失并立即显示未接来电通知。这种级别的功能之所以成为可能,是因为 Viber 做到了。
目前,当有来电时,我会发送静默推送通知。这是我的有效载荷...
aps = {
"content-available" = 1;
};
category = INCOMING;
from = "+15555554220";
收到静默推送后,我正在创建一个像这样的本地通知......
if ([userInfo[@"category"] isEqualToString:@"INCOMING"]) {
NSLog(@"application: didReceiveRemoteNotification: fetchCompletionHandler: Incoming Call Notification Received");
NSLog(@"application: didReceiveRemoteNotification: fetchCompletionHandler: Sending Local Notification For Incoming Call");
// Get Caller Contact Info
NSDictionary *contact = [self findContactInfoForNumber:userInfo[@"from"]];
NSString *message = [NSString stringWithFormat:@"Incoming Call: %@",userInfo[@"from"]];
if (contact != nil) {
message = [NSString stringWithFormat:@"Incoming Call: %@ %@",contact[@"firstName"],contact[@"lastName"]];
}
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithObject:@"Incoming Call" forKey:@"type"];
notification.userInfo = infoDict;
notification.category = @"INCOMING_CALL_CATEGORY";
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
notification.alertBody = message;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = @"ring.m4a";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
然后,一旦呼叫断开,我将针对未接来电发送另一个无声推送通知......
aps = {
"content-available" = 1;
};
category = MISSED;
一旦收到,我将取消所有这样的本地通知......
if ([userInfo[@"category"] isEqualToString:@"MISSED"]) {
NSLog(@"application: didReceiveRemoteNotification: fetchCompletionHandler: Missed Call Notification Received");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
我遇到的问题是,在锁定屏幕上它的行为完全符合我想要的方式。我收到来电通知,当呼叫者挂断电话时,该通知立即从通知中心消失,并出现未接来电通知。但是,当手机位于主屏幕上时。将显示一个横幅,然后播放整个铃声,然后显示未接来电。有谁知道发生这种情况的原因?有没有人有任何解决方案来实现这种级别的功能?正如我之前所说,Vider 应用程序是我希望我的应用程序实现的功能的一个典型示例。
预先感谢您。