2015-07-04 51 views
0

下面的代碼可以從線程中找到(下面的鏈接),我似乎無法將其轉化爲快速解決方案,因爲代碼的缺陷似乎不是一種直觀的修復方法迅速(至少從我的理解)...從解析推送通知中提取消息的快速解決方案

有人可以請幫助翻譯此代碼,我需要能夠從swift中讀取解析推送通知的消息(我相信這個代碼在目標c )

Extract "alert" text from push notification

- (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

有不可替代的第一閱讀文檔:https://developer.apple.com/library/prerelease/ios/documentation/Swift /Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID105 –

回答

1

添加到您的AppDelegate ...

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    PFPush.handlePush(userInfo) 
    if let pushText = userInfo["alert"] as? String { 
     let title = NSLocalizedString("News",comment:"") 
     let alert = UIAlertView(title, message: pushText, delegate: nil, cancelButtonTitle: "Ok") 
     alert.show() 
    } 
} 
+0

完美,謝謝 –