2010-08-11 80 views
1

我已經使用Urban Airship實施了蘋果推送通知服務,並在我的應用程序中成功收到通知。如果我收到警報視圖的通知,如果我在警報視圖中單擊視圖按鈕,它將啓動應用程序。通常它發生在APNS中。但是我的客戶想要的是,如果在RSS提要和警報視圖中發生任何更新,如果我們在警報視圖中單擊視圖,它應該轉到應用程序中的特定提要,不會啓動應用程序。這樣做有可能嗎?是否有可能爲我的應用程序中的特定警報視圖按鈕編寫事件。在iPhone中使用城市飛艇的蘋果推送通知服務

這裏我的示例代碼,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge               | UIRemoteNotificationTypeSound                   | UIRemoteNotificationTypeAlert]; 

     [window addSubview:viewcontrollers.view]; 

     [window makeKeyAndVisible]; 

     NSLog(@"remote notification2: %@",[launchOptions description]); 

     return YES; 

    } 

在這種方法中didFinishLaunchingWithOptions,我不能得到的字典中的值,它總是空值。是否有可能在此方法中獲取字典值(Notification)。

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

      NSString *message = [userInfo descriptionWithLocale:nil indent: 1]; 

      NSLog(@"The message string is %@",message); 

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Remote Notification" message: message delegate: nil cancelButtonTitle: @"ok" otherButtonTitles: nil]; 
      [alert show]; 
      [alert release]; 
     } 

在這種方法中,我可以得到字典值。但是,如果在應用程序中運行時發生更新,則此方法只會調用。

請指導我!

謝謝

回答

4

確實有可能做到這一點。在您的application:didReceiveRemoteNotification方法中,您將傳遞包含所有推送通知數據的NSDictionary。你想要做的是將有效載荷中的一些ID或URL發送到Urban Airship。例如:

{ 
    "aps": { 
     "alert": "New RSS entry" 
    }, 
    "entry_id": "XYZ123" 
} 

然後,您可以編寫代碼並在您的應用程序中獲取正確的提要條目。

+0

+1,@robotadam,比ks的答覆。看到我更新的問題,請提到我做錯了什麼。謝謝。 – Pugal 2010-08-14 10:23:45

+0

我不確定你現在的問題是什麼 - 你有來自推送通知的數據,是的?剩下的看起來像是一個鉤入你的代碼的其餘部分。 – robotadam 2010-08-14 15:12:28

+0

@robotadam - 我想他是說應用程序:didReceiveRemoteNotification只是在應用程序在前臺進行通知時才被調用。 – 2010-08-15 04:17:14

1

當應用程序沒有運行,或者由系統已被終止和應用程序通過通知發佈:

在這種情況下,你必須得到通知字典(這本身是launchOptions的價值):

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006786-CH3-SW18

我想象中的代碼將是這樣的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

    NSDictionary *remoteNotification = (NSDictionary *) [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    if (remoteNotification != nil) { 
      NSString *message = [remoteNotification descriptionWithLocale:nil indent: 1]; 
    }  
}