Initiating new MSMessage from host app?

Let's say I have an existing app that has content that would make sense for the user to send to a friend as an interactive iMessage.


Is there currently any way to initiate the creation of a MSMessage with custom content from the app itself?

It does not look like the MFMessageComposeViewController has been extended to handle the creation of MSMessage objects?


If interactive iMessages can not be created directly in the host app, is it possible to launch iMessage with the app's extension and pass along some data?

I was curious about this as well, specifically being able to share stickers from an external app. You're correct, MFMessageComposeViewController hasn't changed at all for this release. It'd be nice to have a consistent experience for users inside the container app and extension.

This isn't currently possible, but would make for a good enhancement requiest bug report.

Filed my request for this feature as Radar # 27292265. Hope to see this before Beta 4!!

I need that, too. Filed rdar://27345276. Feel free to dupe: http://www.openradar.me/27345276.

Accepted Answer

There is now a MSMessage property on the MFMessageComposeViewController to do exactly this. You should see this in Beta 3.

Thanks, this is really useful. Even better would be if MSMessage adopted the UIActivityItemSource protocol so it could be used in UIActivityViewController.


See Radar 27545031, also on Open Radar (no link to avoid moderation).

Thanks for the bug report! It's with engineering for consideration.

@ortwin or @cwoloszynski - did you get this working. I try to put a MSMesage into MFMessageComposeViewController and it appears blank. This is in Beta 6


Running on device (iPad Pro) and blank meaning I see no MSMessage - I can put text in but it does seem like it's not working.


Am I missing something. This is a Single-View application with Messages and MessageUI frameworks added.


Thanks


My code inside the ViewController.swift:


    
    private func composeMessage() -> MSMessage {
        var components = URLComponents()
        var items = [URLQueryItem]()
        items.append(URLQueryItem(name: "test", value: "food"))
        components.queryItems = items
       
        let layout = MSMessageTemplateLayout()
        layout.caption = "Test Me"
        let message = MSMessage(session: MSSession())
        message.url = components.url
        message.layout = layout
        return message
    }
   
    @objc func actionButtonClicked (sender: UIButton) {
        let composeVC = MFMessageComposeViewController()
        composeVC.messageComposeDelegate = self
       
        composeVC.recipients = []
        composeVC.message = composeMessage()
       
        self.present(composeVC, animated: true, completion: nil)
     }

Seems to work here on my iPhone 6s Plus.

@ortwin - thanks for the response


Do you see anything obviously wrong with my code?


I'm upgarding my 6s Plus (main device) to iOS 10 tonight and I'll try it out there.


Thanks for any help

Hm, what looks strange: you don't define the host part of the URL anywhere. Can you try with a simple static URL to rule this out? Also, I'm always using an image though I doubt that would make a difference.

Thanks ortwin for the help. I have added an " http : // www . example . com " (spaces to avoid moderation) for my components.host and an image to the layout - all of this and it doesn't work on my iPhone 6s+ with Beta 6


Some thing I thought of. So far I created a Single-View Application. I included the MessageUI and Messages framework. I have not added a MessageExtension target to the project - I assume you did this since it sounds like your app has an extension component. A very stupid question - Do you have your app interact with the extension for composing the message? Right now the code you see above is in the App's ViewController class.


Anybody else have an MSMessage sending in a MFMessageComposeViewController - as it sounded like there were a few people in this thread wanting to do this.


Any help would be appreciated - I am really hoping it's just something obvious I have missed.

I have it working with an image in the MSMessage template. But I wouldn't use the constructor with a NSSession


This works with Xcode8b6 and iOS10b6-7


MSMessageTemplateLayout* msgLayout = [[MSMessageTemplateLayout alloc] init];

msgLayout.caption = "something here"

msgLayout.image = image; (UIImage)

MSMessage* message = [[MSMessage alloc] init];

message.layout = msgLayout;

controller.message = message;

@fernando - I tried creating the MSMessage without the MSSession in constructor and I got the same result.


So this is what I did from scratch (in case someone can see something really obviously wrong). Again, any help would be greatly appreciated. It really feels like I'm missing something really obvious.


1. Create a brand new Single-View Application

2. In main.storyboard, create a button in the middle of the screen

3. Ctrl-drag "Touch Up Inside" for the button to my ViewController class to create onTouchUp in code (see below)

4. Wrote the code below

5. Run the app on an iPhone 6s Plus

6. See no MSMessage in the MFMessageComposeViewController


import UIKit
import Messages
import MessageUI
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        /
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    @IBAction func onTouchUp(_ sender: AnyObject) {
        let composeVC = MFMessageComposeViewController()
        let msgLayout = MSMessageTemplateLayout()
        msgLayout.caption = "something here"
        let message = MSMessage()
        message.layout = msgLayout
        composeVC.message = message
      
        self.present(composeVC, animated: true, completion: nil)
    }
}

Problem solved and it was probably obvious to all those who have been working with Extensions for a while. Hopefuly this helps anybody else trying to do this.


I needed to create a Target of MessageExtension in my project.


So to follow my steps:

7. Create a Target of a MessagesExtension

8. Run the app on iPhone 6s Plus

9. See the MSMessage in the MFMessageComposeViewController


I had created my first two iMessage apps as standalone iMessage extensions. This was my first try at an App that would send MSMessage.


Thanks to all who helped!

Initiating new MSMessage from host app?
 
 
Q