我的头衔可能无法准确描述我的问题,所以我道歉。我已经找到了创建此级别功能的解决方案,但我无法找到它。
我正在为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是我希望我的应用程序做的一个主要的例子。
提前谢谢你。