2014-11-23 41 views
0

我正在使用Parse將推送通知發送到我的應用程序。我想要的是,當用戶從鎖定屏幕上輕掃通知或從主屏幕輕擊通知時,它會打開應用程序,並在UIAlert視圖中顯示推送通知的文本。顯示在UIAlert視圖中推送通知文本

我想它會插入應用程序委託的didfinishlaunchingwithoptions方法,但我真的沒有得到關於如何提取警報文本的線索。

任何意見將不勝感激。

所以下面是我的代碼來顯示警報 - 這是工作,但它顯示完整的JSON消息 - 當我嘗試使用objectForKey:@「警報語句試圖提取」警報「部分推送通知,沒有顯示任何警報的消息部分。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    [PFPush handlePush:userInfo]; 
    pushText = [userInfo objectForKey:@"alert"]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"News", "") 
                message:pushText 
                delegate:nil 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles: nil]; 
    [alert show]; 




} 

回答

1

你可以把這段代碼的didFinishLaunchingWithOptions部分,然後在UIAlertView中顯示pushText變量。

NSDictionary *notifKey = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; 

if (notifKey) 
{ 
    pushText = [notifKey objectForKey:@"alert"]; 
}