2014-08-27 103 views
4

根據我的理解,當應用程序正在運行或處於前臺並收到推送通知時,應用程序不應顯示任何提醒,但應用程序代理將調用didReceiveRemoteNotification委託方法和我應該在回調中處理推送通知。當應用程序在前臺運行時收到iOS推送通知

推送通知應該只在應用程序處於後臺時顯示警告/橫幅。

但是,我們的應用程序在應用程序正在運行時或在前臺有時(而不是全部時間)都會通過「確定」按鈕獲取推送通知警報。我想知道這是iOS 7中的新東西(我從來沒有聽說過這個),還是因爲我使用UrbanAirship來爲我們的iOS應用使用alias的推送通知。該應用程序將在運行時顯示推送警報,並在didReceiveRemoteNotification中運行回調。

撓撓我的頭。有誰知道爲什麼?

+0

如果您在收到推送通知時沒有顯示UIAlertView的代碼,聽起來好像是Urban Airship這樣做。 – Mike 2014-08-27 16:16:14

回答

7

當應用程序在前臺時,它不應該顯示任何內容。

如果您看到alertView,則表示您爲其提供了代碼。大意如下

東西:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    UIApplicationState state = [application applicationState]; 

    if (state == UIApplicationStateActive) { 
     //app is in foreground 
     //the push is in your control 
    } else { 
     //app is in background: 
     //iOS is responsible for displaying push alerts, banner etc.. 
    } 
} 

如果您已實現pushNotificationDelegate

[UAPush shared].pushNotificationDelegate = self; 

然後覆蓋,並留下空白

- (void)displayNotificationAlert:(NSString *)alertMessage 
{ 
    //do nothing 
} 
+0

這就是我的問題。我收到2個警報視圖。一個來自我的代碼(與你的代碼相同),另一個來自無處。我想如果城市飛艇負責第二次警報 – imObjCSwifting 2014-08-27 16:24:50

+1

請分享您的代碼 – meda 2014-08-27 16:25:27

+0

是的UA是罪魁禍首。重寫UA處理推送通知的工作。謝謝 – imObjCSwifting 2014-08-27 16:57:49

2

您AR e由於您的代碼中配置了Urban Airship,因此很可能會看到額外的推送通知。從Urban Airship's docs

The sample UI includes an implementation of UAPushNotificationDelegate that handles alerts, sounds, and badges. However, if you wish to customize this behavior, you can provide your own implementation:

[UAPush shared].pushNotificationDelegate = customPushDelegate;

有在處理與城市飛艇in their support articles推送通知的正確方法的更多信息。由於您使用的是UA,因此我建議您在前臺使用其代表等來處理傳入的推送通知,而不是在didReceiveRemoteNotification應用程序委託方法中實現自己的代碼。

希望這有助於...如果沒有,請發佈您的代碼,以便我們可以解密發生了什麼。這確實是非常奇怪的行爲!

+0

這一個應該是正確的。你也可以刪除UI代碼,或者在這裏註釋掉UIAlertView:https://github.com/urbanairship/ios-library/blob/master/Airship/UI/Default/Push/Classes/Shared/UAPushNotificationHandler.m #L33 – dperconti 2014-08-28 17:41:11

相關問題