Code Wizards

Yeet Into OnSong

With URL schemes you can open other apps, as long as you can figure out how to structure the URL. You can also open OnSong using the UIDocumentInteractionController when you pass a file type that OnSong® can open. Mind. Blown.

Website Link

Openin’ content into apps is hard, ’cause who knows if the app is even there? So we built an import endpoint on the onsongapp.com website. Make yourself a sample link with these bleepin’ directions:

  • Visit onsongapp.com/import for a lazy way to make the link. You’re welcome.
  • Type in the web address of the file you want to shove into OnSong® & hit submit. Easy peasy, amirite?
  • OnSong will sniff around the web with an HTTP HEAD method to grab the filename & size. Nosy? Yes. Effective? Also yes.
  • If a HEAD operation isn’t supported on the content, OnSong just guesses the file type & file name from the URL. Totes magic. Don’t ask.
  • You’ll get a preview of the link plus a button to copy it, which is freakin’ easy to create with code. Even your cat could do it.

URL Scheme: Link Voodoo

You can use a URL on an iOS device to open OnSong & do import stuff. Type the following URL into Safari’s location bar & iOS will open OnSong. ZOMG, it’s like magic but with more typing.

Openin’ OnSong® from another app? Y’all gotta add the onsong: schema to your device’s list of approved schemas. Rules are rules, peeps.

onsong://

Wanna open OnSong from your very own iOS app? Mash these Objective-C statements together to see if the user has OnSong installed, & if so, open it from inside your app. Coders gonna code.

// See if the user has OnSong installed
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"onsong://"]]) {

    // Open OnSong from your app
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"onsong://"]];
}

Got a supported file format sittin’ on your website? Swap the http:// part of the URL with onsong:// to open OnSong & ask the user to import the file. Usin’ SSL? Then redirect to the https:// location of the file, since OnSong checks the http:// location first. Yeah, we’re picky.

onsong://my.domain.com/files/go/here/Song%20Title.txt

Sometimes the file isn’t on a web server. Maybe you’re makin’ it inside an app & wanna toss it to OnSong without parkin’ it somewhere public first. Or maybe the content is locked down for authenticated users only. Fancy! For those cases, OnSong can also import files using a Base64-encoded file with a syntax like this:

onsong://ImportData/My%20Song%20Title.pdf?BASE_64_ENCODED_DATA_HERE

For example, click this link to import Welcome To OnSong as a PDF file. Go on. Click it. We dare you.

OnSong uses the file extension you hand it to decide how to treat each file. Generatin’ content on the fly? Send a filename by setting a Content-Disposition HTTP header. Otherwise it’s guesswork, & nobody likes that.