2013-10-24 40 views
1

我是iOS開發新手。我想在應用處於非活動狀態時收到推送通知時顯示alertview。如何在應用未啓動時接收推送通知時顯示alertview?

Apple表示,推送通知可以以警報消息的形式呈現,或者他們可以標記應用程序圖標。

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

我使用PushSharp發送推送通知。但通知只能在通知中心看到。我應該怎麼做才能在alertview上顯示它?

我知道我們可以寫一個代碼來顯示alertview像

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"test title" message:@"test message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
     [alert show]; 

} 

但我點擊通知和應用程序啓動後,執行該代碼。一旦設備收到推送通知,我想立即顯示alertview

還有一個問題,蘋果支持任何方式來執行接收推送通知的代碼,雖然應用程序沒有啓動?

任何想法?

回答

0

UIAlertView不可能。你可以通過UILocalNotification來完成你的任務。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    notifaication = [[UILocalNotification alloc] init]; 
    notifaication.timeZone = [NSTimeZone systemTimeZone]; 

    notifaication.alertBody = // Set the Body 
    notifaication.alertAction =// @"Show me"; 
    backupAlarm.soundName = UILocalNotificationDefaultSoundName; 
} 

欲瞭解更多信息over_Here

+0

請注意,應用程序:didReceiveRemoteNotification:當一個推送通知來當你的應用程序是在前臺或者如果用戶選擇與通知交互被調用。 –

+0

感謝您的回答庫馬爾! –

相關問題