The power of openURL

Hello,
Everyone’s been talking about the power of http.get/request, but nobody’s talked about the power of openURL(). I decided to demonstrate it myself. Her’s the code:


-- Use this function to perform your initial setup
function setup()
    print("Drag the slider above to change the URL type. Toich the screen to open that URL.")
    iparameter("URLType", 1,12)
    watch("url")
    watch("description")
    url = nil
    description = ""
end

function draw() 
    background(40, 40, 50)
    strokeWidth(5)
    
    if URLType == 1 then
        --openURL('http://twolivesleft.com/Codea')
        url = "http://twolivesleft.com/Codea"
        description = "This will just open up a normal website."
    elseif URLType == 2 then
        --openURL('maps://')
        url = "maps://"
        description = "This will open up to the maps app."
    elseif URLType == 3 then
        --openURL('tel://')
        url = "tel://"
        description = "If you were on an iPhone, this would open up the phone app, but you're probably on an iPad, so this does nothing."
    elseif URLType == 4 then
        --openURL('sms://')
        url = "sms://"
        description = "This will open up the iMessages app."
    elseif URLType == 5 then
        --openURL('mailto://simeon@twolivesleft.com?subject=Look%20what%20I%20did%20with%20Codea!&body=Codea%20is%20AMAZING!')
        url = "mailto://simeon@twolivesleft.com?subject=Look%20what%20I%20did%20with%20Codea!&body=Codea%20is%20AMAZING!"
        description = "This will open up a little email for you."
    elseif URLType == 6 then
        --openURL('music://')
        url = "music://"
        description = "This will open up your music app."
    elseif URLType == 7 then
        --openURL('youtube://')
        url = "youtube://"
        description = "This will open the youtube app for you."
    elseif URLType == 8 then
        --openURL('videos://')
        url = "videos://"
        description = "This will open up your video's app."
    elseif URLType == 9 then
        --openURL('http://itunes.com/apps/Codea')
        url = "http://itunes.com/apps/Codea"
        description = "This will open uo the app store."
    elseif URLType == 10 then
        --openURL('http://itunes.apple.com')
        url = "http://itunes.apple.com"
        description = "This will open iTunes."
    elseif URLType == 11 then
        --openURL('ibooks://')
        url = "ibooks://"
        description = "This will open up iBooks."
    elseif URLType == 12 then
        --openURL('http://wiki.akosma.com/IPhone_URL_Schemes')
        url = "http://wiki.akosma.com/IPhone_URL_Schemes"
        description = "Opening up this link will direct you to a page with more details on URL schemes for iOS. It will also list some of the 3rd party app URL schemes."
    end
end

function touched(touch)
    openURL(url)
end

```

I didn't look into the details of the variables of each URL, but I plan to. I'll probably update this so you can do something like type in the URL to open, compose an email, type in the song to open, etc. Hope this helps!  
Thanks!

Wow thats is amazing, can i open an specifies application? Like mmm… facebook?

Open #12. It has examples of a lot of 3rd party URL scheme examples. Here’s the link to Facebook:
http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
It’s really descriptive of it’s attributes, so good luck.

This had crossed my mind when I first saw openURL(). It will be very useful when it comes to doing things like requesting bug reports and such. One thing I would love to see in openURL is the ability to select whether to open in Safari or in the in-app browser, like the way the forums button works in Codea.

@Deamos - Good idea. You can open it in 3rd part browsers like Opera Mini (by doing ohhtp:// and ohttps://) but that’s not an in app browser.

openURL can be used to open the web sites in the in-app browser, just by adding “true” as a parameter for “internal browser”

Just like this -
openURL(url, true)

@JustPlaying - True, but that could result in strange results if the link doesn’t work.

Just an update: Some new stuff in iOS 7 mail program: http://www.macstories.net/tutorials/ios-7-and-mail-message-urls/

First sorry for bumping this thread, but I was wondering… Could openurl also be used to recieve some kind of feedback info? Like some games have a ‘like on facebook for free gems’ option, I was wondering if such a thing would be possible from within codea as well

@stevon8ter - This is not possible with openURL. Sorry!

@zoyt ok, i was just wondering :wink:

Code so you don’t get the unfinished string error

 
 
-- Use this function to perform your initial setup
function setup()
    print("Drag the slider above to change the URL type. Toich the screen to open that URL.")
    iparameter("URLType", 1,12)
    watch("url")
    watch("description")
    url = nil
    description = ""
end
 
function draw() 
    background(40, 40, 50)
    strokeWidth(5)
    
    if URLType == 1 then
        --openURL('http://twolivesleft.com/Codea')
        url = "http://twolivesleft.com/Codea""
        description = "This will just open up a normal website."
    elseif URLType == 2 then
        --openURL('maps://')
        url = "maps://"
        description = "This will open up to the maps app."
    elseif URLType == 3 then
        --openURL('tel://')
        url = "tel://"
        description = "If you were on an iPhone, this would open up the phone app, but you're probably on an iPad, so this does nothing."
    elseif URLType == 4 then
        --openURL('sms://')
        url = "sms://"
        description = "This will open up the iMessages app."
    elseif URLType == 5 then
        --openURL('mailto://simeon@twolivesleft.com?subject=Look%20what%20I%20did%20with%20Codea!&body=Codea%20is%20AMAZING!')
        url = "mailto://simeon@twolivesleft.com?subject=Look%20what%20I%20did%20with%20Codea!&body=Codea%20is%20AMAZING!"
        description = "This will open up a little email for you."
    elseif URLType == 6 then
        --openURL('music://')
        url = "music://"
        description = "This will open up your music app."
    elseif URLType == 7 then
        --openURL('youtube://')
        url = "youtube://"
        description = "This will open the youtube app for you."
    elseif URLType == 8 then
        --openURL('videos://')
        url = "videos://"
        description = "This will open up your video's app."
    elseif URLType == 9 then
        --openURL('http://itunes.com/apps/Codea')
        url = "http://itunes.com/apps/Codea""
        description = "This will open uo the app store."
    elseif URLType == 10 then
        --openURL('http://itunes.apple.com')
        url = "http://itunes.apple.com""
        description = "This will open iTunes."
    elseif URLType == 11 then
        --openURL('ibooks://')
        url = "ibooks://"
        description = "This will open up iBooks."
    elseif URLType == 12 then
        --openURL('http://wiki.akosma.com/IPhone_URL_Schemes')
        url = "http://wiki.akosma.com/IPhone_URL_Schemes""
        description = "Opening up this link will direct you to a page with more details on URL schemes for iOS. It will also list some of the 3rd party app URL schemes."
    end
end
 
function touched(touch)
    openURL(url)
end