Check if app installed

Hi all,

I was wondering if someone could help or point me in the right direction. Is there a way to check whether an app like Facebook is installed on the device? I wanted to create a hyperlink in my app and need to know if I should use the fb://profiles/xxx URL or www.facebook.com/xxx.

Any help is much appreciated.

Regards

Stuart

@Stuart010, Here’s @zoyt’s example of opening apps with openUrl http://codea.io/talk/discussion/1123/the-power-of-openurl/p1
and here’s a list of device/app urls
http://wiki.akosma.com/IPhone_URL_Schemes .
Btw, welcome to the forums

There’s a better way. I don’t know the details, but with file IO in Lua you an get a list of the apps installed, by some ID. If you can find the ID that matches FaceBook and check for that folder, that’ll work. I’m sorry I don’t know the details.

@Zoyt i doubt you can get any app folder name without the jailbreak…? the basic protection in ios is that folder names are really complex.

@Jmv38 - Try fooling around with file IO like on this thread: http://codea.io/talk/discussion/4608/file-io/p1
Try navigating outside your Documents folder. At least in iOS 6, it worked, but I don’t have my iPad to test it.

Here’s what I wrote, but I think Jmv is right about the set of numbers and letters being unique, and since I can’t get a list of directories in Applications to check them all, it isn’t really possible to find the right one.

function setup()
    print(downloadedFacebook())
end

function downloadedFacebook()
    local rt = false
    local dirn = "private/var/mobile/Applications" .. "/B4E99996-DA19-417D-8D48-803CEE29D263/Facebook.app"
    local dire = io.open(dirn, "r")
    if dire ~= nil then 
        rt = true
        io.close(dire)
    end

    return rt
end

@kirorp was partially right. I decided to look it up, and the best way to do it is test for is the app can be opened by its URL scheme (if the one your looking for has one). However, you need to make an Objective C add on to do that. Here’s the chunk of Objective C code to test a URL scene:

BOOL temp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourAppURL://"]];
            
if(!temp)
{
    NSLog(@"INVALID URL"); //Or alert or anything you want to do here
}

Hope that helps!

Thanks guys, some good responses and something to think about. I’ll let you know how I get on.

Stuart