I've been trying to create an iMessage companion app that makes it easier to share data from my main app, but I'm having trouble figuring out how to approach this.
I've tried using MSConversation's
insertAttachment(URL, withAlternateFilename: String?, completionHandler: ((NSError?) -> Void)? = nil)
method to send file attachments (whose extension my app is registered to open). The message sends and receives fine, but there seems to be no way to open custom attachments from Messages in my app. These files open my app just fine if loaded in Mail, Safari, etc...
Therefore, I turned to using MSMessage and having that interact with my iMessage app. It looks like the only way to send data with an MSMessage instance is to use the url property. I used NSURLComponents and NSURLQueryItems to encode data into the message's url object. However, when the length of the value property of any one of my NSURLQueryItems exceeds a certain amount, insert(message: MSMessage) fails with the following error:
The operation couldn’t be completed. (com.apple.messages.messagesapp-error error 8.)
This happens even though the NSURLComponents object was created just fine with data of any size I tried.
So I guess this leaves me with a few questions...
1: Is this a bug? If so, ignore the next questions and I'll be happy to submit a bug report.
2: If this isn't a bug and there is indeed a size limit for URL objects sent via MSMessage, why isn't it documented?
3: If this isn't a bug, why is there a size limit for MSMessages when the same amount of data can be send as attachments?
Thanks.
EDIT: The longest length string I was able to put into a MSMessage url query item without failing upon inserting that message is 5114 characters long. Strings with 5115 or more characters seem to fail consistently.