Opening other apps from Corona App

I am building a business app and would like to do the following:

  1. Like us on Facebook: should open their FB page in the Facebook app

  2. Follow us on Twitter: should open their twitter profile page in the twitter app

  3. Get directions to the store: should open the map app (or Google maps app) with directions to pre-filled store location

I have found drips and drabs on how to do some of this (mainly the FB one although it crashes the FB app when I try it). I also read in another forum post that the URL schemes with system.openURL() is broken in iOS9 (https://forums.coronalabs.com/topic/59503-changes-to-calling-url-schemes-via-systemopenurl-under-ios9/?hl=%2Bopen+%2Bother+%2Bapps).

I can currently just open each link in the web browser but this doesn’t give the “cool factor” of opening the different apps.

Can anyone provide the answer on how to do each one? And will it still work under iOS9?

Thanks!

I too am curious about this, Being able to open pages/word would be really useful

The problem is you (presumably) don’t know whether or not FB, Twitter, and Google Maps are installed.

Corona offers ways to do all those things programmatically from inside your app: the facebook.* library, etc. 

The facebook.* library will open the FB app if available and if not open the FB site within a browser.

Opening things like the facebook app can be done with system.openURL(). I don’t believe it’s broke in iOS 9, but you may need to include some things in your build.settings.  See: https://coronalabs.com/blog/2015/09/17/about-app-transport-security-ats/

We don’t document all of the various URL scheme’s supported by all the possible vendors. You can google to see how to deep link to a facebook page.

Follow us on twitter could be done via an openURL, but most people would use Twitter’s API to provide a Follow Us button and make the API call behind the scene instead of opening a webpage.

Thanks Rob,

I was under the impression that the URL schemes were Corona specific. I’m sure most of the developers here knew that is not the case already, but for the few like me who did not, that helps immensely.

So a quick Google search found me this great page: Top 10 iOS App Deeplink Schemas for Mobile and SocialMarketers. This helps avoid using APIs for the simple process of what I wanted to do.

As far as maps:

[lua]

local function urlencode(str)

   if (str) then

      str = string.gsub (str, “\n”, “\r\n”)

      str = string.gsub (str, “([^%w])”,

         function © return string.format ("%%%02X", string.byte©) end)

      str = string.gsub (str, " ", “+”)

   end

   return str    

end

local function onGetDirections()

  local loc = urlencode(“My Address, My Town, My State”)

  if ( model == “iPhone” or model == “iPad” ) then

    system.openURL(“http://maps.apple.com/?q=”…loc)

  else

    system.openURL(“comgooglemaps://?q=”…loc)

  end

end

[/lua]

I have a check for device in there but that Google link actually works on iOS if you have the Google App installed. Also, I tried using “daddr=” instead of “q=” for the Apple Maps link as they suggest to use to get directions but the Maps app would crash every time. I don’t know why.

That code seems to work for now but I have not yet tested in iOS9.

Hope that helps!

I too am curious about this, Being able to open pages/word would be really useful

The problem is you (presumably) don’t know whether or not FB, Twitter, and Google Maps are installed.

Corona offers ways to do all those things programmatically from inside your app: the facebook.* library, etc. 

The facebook.* library will open the FB app if available and if not open the FB site within a browser.

Opening things like the facebook app can be done with system.openURL(). I don’t believe it’s broke in iOS 9, but you may need to include some things in your build.settings.  See: https://coronalabs.com/blog/2015/09/17/about-app-transport-security-ats/

We don’t document all of the various URL scheme’s supported by all the possible vendors. You can google to see how to deep link to a facebook page.

Follow us on twitter could be done via an openURL, but most people would use Twitter’s API to provide a Follow Us button and make the API call behind the scene instead of opening a webpage.

Thanks Rob,

I was under the impression that the URL schemes were Corona specific. I’m sure most of the developers here knew that is not the case already, but for the few like me who did not, that helps immensely.

So a quick Google search found me this great page: Top 10 iOS App Deeplink Schemas for Mobile and SocialMarketers. This helps avoid using APIs for the simple process of what I wanted to do.

As far as maps:

[lua]

local function urlencode(str)

   if (str) then

      str = string.gsub (str, “\n”, “\r\n”)

      str = string.gsub (str, “([^%w])”,

         function © return string.format ("%%%02X", string.byte©) end)

      str = string.gsub (str, " ", “+”)

   end

   return str    

end

local function onGetDirections()

  local loc = urlencode(“My Address, My Town, My State”)

  if ( model == “iPhone” or model == “iPad” ) then

    system.openURL(“http://maps.apple.com/?q=”…loc)

  else

    system.openURL(“comgooglemaps://?q=”…loc)

  end

end

[/lua]

I have a check for device in there but that Google link actually works on iOS if you have the Google App installed. Also, I tried using “daddr=” instead of “q=” for the Apple Maps link as they suggest to use to get directions but the Maps app would crash every time. I don’t know why.

That code seems to work for now but I have not yet tested in iOS9.

Hope that helps!