Search code examples
iosobjective-cswiftimessageios-extensions

Open iMessage from my application


Is there any way to open iMessage apple app from my app? I don't need any composers, the main idea is to open actual iMessage with my extension.

EDITED

I don't want to send any messages; I need only iMessage App to be opened


Solution

  • this can be done as follows (in Swift 2):

    let phoneNumber = "958585858"
    let text = "Some message"
    
    guard let messageURL = NSURL(string: "sms:\(phoneNumber)&body=\(text)") 
    else { return }
    if UIApplication.sharedApplication().canOpenURL(messageURL) {
        UIApplication.sharedApplication().openURL(messageURL)
    }
    

    and if you only need to open messages app :

    guard let messageAppURL = NSURL(string: "sms:")
    else { return }
    if UIApplication.sharedApplication().canOpenURL(messageAppURL) {
        UIApplication.sharedApplication().openURL(messageAppURL)
    }
    

    make sure to add sms: to LSApplicationQueriesSchemes in your Info.plist