galway
galway

Reputation: 269

Can we share msmessage without develop an imessage extension?

I saw there is message property in MFMessageComposeViewController. Can we construct an MSMessage and assign it to MFMessageComposeViewController, then share this message in new iMessage App without developing an extension? If we can do that, we can share other with a message with images and title, instead of just plain string or attachment before iOS 10.

Upvotes: 2

Views: 488

Answers (1)

galway
galway

Reputation: 269

From what I learn here https://forums.developer.apple.com/thread/49922, you need to create an imessage extension target (you don't need to do any develop for the target) , then you can share the msmessage in MFMessageComposeViewController

This is the demo in the link above:

  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

    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)  
        }  
    }  
    
    1. Create a Target of a MessagesExtension
    2. Run the app on iPhone 6s Plus
    3. See the MSMessage in the MFMessageComposeViewController

Upvotes: 1

Related Questions