Forum Archive

Accessing obj-c help

alijnclarke

So I'm trying to access the functionality of an objective-c class,

The objective-c code i'm trying to replicate is:

NSArray *apps = [[LSApplicationWorkspace defaultWorkspace] allInstalledApplications];

currently I can do this:

appWorkspace = ObjCClass('LSApplicationWorkspace')
default = (appWorkspace.defaultWorkspace)

But I can't find a way to access the 'allInstalledApplications' method.. any ideas?

omz

Your defaultWorkspace call is missing parentheses. It should be appWorkspace.defaultWorkspace().

alijnclarke

Can't believe i missed that! Thank you!

Great app btw, very impressive indeed

brumm

I'm curious. In which way I have to use NSArray?

apps = list(default.allInstalledApplications())
for app in apps:
    print app
alijnclarke

You need to look up the documentation for

allInstalledApplications

You're currently accessing it wrong

brumm

I'm an absolute noob with objective-c, so I hoped I can learn from an example.

omz

@brumm Your code doesn't look wrong to me (what do you mean exactly, @alijnclarke?), but I don't really understand your question.

brumm

In objective-c the result is stored in a NSArray.
I thought I can access the single entries, but with the code above I got a single string looking like
com.apple.AppStore
...
Is there a way to get only the name of the application?

filippocld

Just put this instead of print app

print app.applicationIdentifier()
brumm

Great, thanks a lot.

alijnclarke

Sorry for the vague reply, was in a rush!

There's a couple of options (could be more, but these are all I've needed to use)

app.bundleURL()
app.bundleExecutable()
app.bundleIdentifier()
app.applicationType()
app.bundleContainerURL()
app.dataContainerURL()
app.localizedName()
lukaskollmer

Here you go:

brumm

Perfect, thanks a lot.

lukaskollmer

By the way, isn't that a huge security loophole? You can easily list all installed applications, get all installed URL schemes, and open any app by bundle ID without the usual user prompt to allow this.

I mean, for scripting and automation this is awesome, but even the private [UIApplication -launchApplicationWithIdentifier: suspended:] requires your apps to have root access and define some SpringBoard entitlements.

alijnclarke

It wouldn't get approved by apple as it's a a private api and it's pretty obscure to find.

There's lots of interesting things in the private api's if you go looking!!

omz

@lukaskollmer I would be very surprised if this API isn't shut down for third-party apps in one of the next iOS updates. While it is a private API, and you wouldn't get through app review calling it directly, there are obviously lots of ways you could get around those checks...