如何提取推送通知的部分内容?

时间:2015-12-25 07:38:35

标签: ios swift push-notification

我现在可以在推送通知中提取整个消息,但我想取出部分消息。我该怎么办?以下是取出整个邮件的代码。所以打印出来的结果是Bob wants you to listen to Breezeblocks by Alt-J,我想提取Breezeblocks和Alt-J。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

 if let launchOptions = launchOptions as? [String : AnyObject] {
    if let notificationDictionary =     launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
        self.application(application, didReceiveRemoteNotification: notificationDictionary)
        let text = launchOptions["aps"]!["alert"]
        print(text)


    }
    }

    return true
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    PFPush.handlePush(userInfo)
    let text = userInfo["aps"]!["alert"]
    print(text)

}

 func pushNotifications(){

      let data = [ "alert" : "\(username!) wants you to listen to \(titleofsong) by \(artist)",
        "identifier":"PlayerController"
    ]


    let userQuery: PFQuery = PFUser.query()!
    userQuery.whereKey("objectId", containedIn: Array(setOfSelectedFriends)) 

    let pushQuery: PFQuery = PFInstallation.query()!
    pushQuery.whereKey("user", matchesQuery: userQuery)

    let push = PFPush()
    push.setQuery(pushQuery)
    push.setData(data)

    push.sendPushInBackgroundWithBlock {
        success, error in

        if success {
            print("The push succeeded.")
        } else {
            print("The push failed.")
        }
    }

}

1 个答案:

答案 0 :(得分:0)

你可以试试这个。

  1. 设置数据:

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoggingInterceptor());
        registry.addInterceptor(new TransactionInterceptor()).addPathPatterns("/person/save/*");
    }
    
  2. 收到这样的解析时:

    let data = ["alert" : "\(username) wants you to listen to \(titleofsong) by \(artist)",
        "identifier":"PlayerController",  "title" : "\(titleofsong)", "artist" :  "\(artist)"]
    
  3. 在Parse中推送通知您可以引用Push notification in Parse

    希望这有帮助!