用于从解析推送通知中提取消息的快速解决方案

时间:2015-07-04 02:35:31

标签: ios swift parse-platform apple-push-notifications

下面的代码可以从线程(下面的链接)中找到,我似乎无法将其转换为快速解决方案,因为代码的缺陷似乎不是swift中的直观修复(至少从我的理解)。 ..

有人可以帮助翻译这段代码,我需要能够从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 个答案:

答案 0 :(得分: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()
    }
}