0

How to get body and title data from the below response. I'm totally stuck

[aps: {

    alert =     {
        body = test123;
        title = test123;
    };
 }, 
 gcm.message_id: 0:4a]
4
  • if let dict = userInfo[0] as? [String:AnyObject] { print(dict) } Commented Jan 23, 2017 at 12:21
  • I'm asking is, the Response you have added is showing from the print(dict)? Commented Jan 23, 2017 at 12:26
  • @Nirav I'm getting nil value for that. can u help me out Commented Jan 23, 2017 at 12:29
  • Check my answer once. Commented Jan 23, 2017 at 12:30

1 Answer 1

1

If you are working with notification then you need to access the data like this way.

if let info = notification.userInfo as? [String: AnyObject],
   let apsDic = info["aps"] as? [String: AnyObject], 
   let alertDic = info["alert"] as? [String: AnyObject] { 
      if let body = alertDic["body"] as? String {
          print(body)
      }
      if let title = alertDic["title"] as? String {
          print(title)
      }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@ThripthiHaridas Welcome mate :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.