swift 从解析推送通知中提取消息的解决方案

swift solution for extracting message from parse push notification

下面的代码可以从线程中找到(link 下面),我似乎无法将其转化为 swift 解决方案,因为代码的缺陷似乎不是一个直观的修复在 swift(至少根据我的理解)...

有人可以帮忙翻译这段代码吗,我需要能够从 swift 中的解析推送通知中读取消息(我相信这段代码会在 objective 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];

}

将此添加到您的 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()
    }
}