Rapsefar Rapsefar - 1 year ago 90
Swift Question

Store a variable in a conversation in iMessage Apps

I'm completly new to developing iMessage Apps.

I would like to store a shared variable (let's say an Int) to a conversation. The Use case could be an incrementing integer, that is incremented every time a message is send from any participant in the conversation.

Is this posible?

I have searched for this this without any luck.

sks sks
Answer Source

You can attach shared variable in URL .

//Insert the URL when user send the Message .

   let message = MSMessage()
    message.layout = layout
    message.url = URL(string: "application/sharedVariable=X")
    self.activeConversation?.insert(message, completionHandler: { (error) in

You can extract above shared Variable from above URL .

  let url = "http://application/sharedVariable=X" 
  let queryItems = URLComponents(string: url)?.queryItems
  let sharedValue = queryItems?.filter({$0.name == "sharedVariable"}).first          

If you do not want anyone to know the shared Variable then you can encrypt while sending.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download