2015-05-21 26 views
2

從iOS8上,就可以顯示在UILocalNotification UILocalNotification iOS8啓動時,一個電話在後臺從通知中iOS8上

而且在我的應用我有一個選項叫警察了一些提示選項。據我所知,從後臺撥打電話是不可能的,那麼你有什麼建議?我可以啓動應用程序然後觸發電話嗎?或者還有其他的選擇嗎?

+1

ü可以啓動應用程序並調用 – Mukesh

回答

1

如果要在推送通知到達時在後臺線程(未掛起)中執行操作,則需要在推送通知有效內容中發送「content-available」:@「1」。有了這個,你將能夠在後臺應用程序時處理

你可以在用斷點實現這個之後進行測試。 當應用運行但在後臺時發送推送通知。

內容提供

+0

它的計劃'UILocalNotification' – androniennn

+0

一個簡單,你可以,如果你的應用程序使用的位置,palying音頻呼叫從背景的方法...... https://developer.apple.com /library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html –

+0

好的,我們可以啓動一個方法,但我們無法啓動電話應用程序來撥打電話。 – androniennn

1

於是,我找到了一個解決方案: 在聲明UIMutableUserNotificationAction,你應該設置它的激活模式UIUserNotificationActivationModeForeground

UIMutableUserNotificationAction *notificationAction1 =[[UIMutableUserNotificationAction alloc] init]; 
    notificationAction1.identifier = @"identifier1"; 
    notificationAction1.title = @"identifier1"; 
    notificationAction1.activationMode = UIUserNotificationActivationModeForeground; //HERE the tip 
    notificationAction1.destructive = NO; 
    notificationAction1.authenticationRequired = NO; 

然後在您的AppDelegate方法:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler { 
    if ([identifier isEqualToString:@"identifier1"]) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 
} 
} 

就是這樣!