15

I declared an url scheme in my app, smstest so in Safari I can write in the search bar smstest:my-testor smstest://my-test and my app is open.

I'm trying to achieve the same from a SMS text so the Messages app would format smstest:my-test or smstest://my-test as a link and the user could tap it and my app being called. But the text is not formatted as a link.

Is it possible or the only solution to open an app from a SMS is to point to an Internet page with a script?

Thank you.

EDIT: funny thing, I have installed IMO Messenger and I receive a SMS with a code as an URL scheme, and that is parsed by Messages app as a link. Why does not happens with my app? I tried with several messages, with spaces before and after the url and nothing happens.

emenegro
  • 6,901
  • 10
  • 45
  • 68

2 Answers2

20

In general there is standard way to open application from Messages app by using url scheme:

  1. Add url scheme to info.plist file: my-scheme.
  2. Install application to the target iPhone.
  3. Send SMS with text like this: "my-scheme://it-is-my-scheme.

And everything works well. But it is possible one interesting case when it doesn't work and you think that source code is wrong. But it isn't so. Let's try to investigate this case:

  1. Before adding url scheme and installing application send SMS. As it expected message will be displayed as plain text:
    First SMS

  2. Now lets add url scheme to info.plist:
    Info.plist

  3. Finally install application and send/receive the same SMS:
    Second SMS

As you see last message is displayed like link and if I tap on it then iOS opens my application. But the first message is still displayed as plain text and it isn't tappable. It seems that the logic of Messages app is implemented in such manner.

Now lets delete application from iPhone and send the same SMS one more time:
Third SMS
Now it again displayed as plain text but the second message - as link. And if I tap on it iOS does nothing and leaves Messages app opened.

Conclusion: Be sure that you send/receive SMS after installing application that supports your scheme. Only in this case it will be displayed as link and user can open your application by tapping on it.

Notice: I also catch one case when at the beginning application was installed without supported url schemes and then when I add this support message has been displayed as plain text but not as link. I can't reproduce it. But if above steps won't help to resolve your issue try:

  1. Remove application from iPhone;
  2. Change url scheme (or even change both: url scheme and bundle id as a last resort);
  3. Install it again;
  4. Send SMS with new url scheme.
Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
  • I think my problem is what you explained and the steps I took to make my tests. Now the scheme is perfectly parsed and all works perfect. Great answer, thank you. – emenegro Apr 23 '14 at 06:16
  • Hi, I have a doubt here. Here, in the above example "Stack-overflow" is the value of URL Scheme. What's hi-there? A normal text message? I have sent similar text, but it is coming as just text and not as link. – nOOb iOS Jan 15 '15 at 15:58
  • @Fr33KiLL, yes, "he-there" it's just text, it works as url, you can add your parameters: stack-overflow://hi-ther?p1=1&p2=2 and then parse it in app. "stack-overflow" - the same string as in URL Schemes in Info.plist file. "://" - is required. – Vlad Papko Jan 15 '15 at 17:07
  • Hi Can any one say how can i open that link in browser if the app does not installed? – kalyani puvvada Jan 18 '17 at 12:45
5

EDIT:

I have just tried with an app sending my url scheme on the sms body and worked. It must have this format smstest://my-test

The app have to be installed and with the url scheme declared on the info.plist when you receive the sms to work.

I add the screenshot of an SMS received with different url schemes, all of them recognized by the iPhone SMS app

SMS URL SCHEMES

If it still doesn't work, try implementing and make them return YES

application: handleOpenURL: and application: openURL:sourceApplication: annotation:

- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return YES;
}

This old answer was for the JS redirection you asked for on the comments.

I use this for redirecting from web to app with fallback to the itunes url in case the app isn't installed

var now = new Date().valueOf();
setTimeout(function () {
    if (new Date().valueOf() - now > 100) return;
    window.location = "http://itunes.apple.com/yourappurl";
}, 25);
window.location = "smstest://my-test";
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • Having "my-test" appended to the end of smstest://my-test is what worked for me. Without it the links didn't get generated in the SMS. – templeman15 May 01 '18 at 16:42