iOS How to use Entitlement.plist to specify property of my app
Asked Answered
P

1

6

I'm using Jailbreak + Appsync + iOS5.0.1 device (without a developer license but with some tricks I can run my app on the device)

Now I want to use a private API launchApplicationWithIdentifier:suspended:. So I need to add

<key>com.apple.springboard.launchapplications</key>
<true/>

to myApp.entitlements.plist file. Then it should work but I still got the error

'Receiver type 'UIApplication' for instance message does not declare a method 
 with selector 'launchApplicationWithIdentifier:suspended:''

Then I found someone said, code signing must be enable if I want to use Entitlements.plist. Is it true? I must have a developer license?

Or is there any other way to use this method? I read some method about how to use private API. It seems difficult. I'm new to iOS development.

Thank you.

Portuna answered 17/6, 2012 at 6:17 Comment(1)
note: if you're wondering why I said "I don't know" to your other question, but answered this one, it's because your other question specified using Xcode. this one did not. I currently only know how to do this outside of Xcode. I normally build with Xcode (with no code signing), and then code sign outside of Xcode (with ldid) when building jailbreak apps.Middlebrow
M
5

I see two problems/questions in your post:

1) you get the error

'Receiver type 'UIApplication' for instance message does not declare a method with selector 'launchApplicationWithIdentifier:suspended:''

Is that a compiler error? It sounds like maybe it is. Here's the thing. There's plenty of objective-c classes in the set of Public Frameworks that still have some private methods in them. Thus, in the normal headers (.h files) for the public frameworks, those private methods won't be listed. But, they're there in the dynamic libraries. If you want to build an app that uses these, then one way to solve the problem is to find a copy of the full header.

For example, here's a copy of the full UIApplication.h header.

Then, you can copy the declaration of the private methods, and in your own code, declare them like so:

// Used to disable warning for non-public methods
@interface UIApplication (Extensions)
  - (BOOL)launchApplicationWithIdentifier:(id)identifier suspended:(BOOL)suspended;
@end

That should stop the compiler from complaining that the private method doesn't exist.

For the future, you should read about class-dump, which is a tool that you can run on the public or private frameworks in the SDK, and reverse generate headers like the one above, yourself. They'll change with every release of the SDK, so it's good to be able to generate them yourself.

2) you ask about using entitlements without code signing.

First, read what Saurik originally wrote about it here. Yes, you do need to code sign the entitlements. But, no, it doesn't have to be with an Apple certificate on jailbroken phones. You can fake code sign, by downloading the ldid executable, and doing

cd MyAppName.app
ldid -Sentitlements.xml MyAppName

assuming your app is named MyAppName and you made the entitlements file entitlements.xml. I believe that this entitlements file would work for you, if you fake code-signed it with ldid:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.springboard.launchapplications</key>
    <true/>
  </dict>
</plist>

Be careful. I have found ldid on the internet in a couple places. I'm really not sure which one is the right one. I recall that once, I tried to do this, and the version of ldid I was using did not work for signing entitlements. I downloaded ldid from another source, and then it worked. So, beware.

Middlebrow answered 19/6, 2012 at 2:0 Comment(2)
Thank you for your reply. Finally I succeed, you can read this link. For the first point. If I import UIApplication that I generated with class-dump, I got "redefinition error". For the second point, I didn't try it but it seems ok:-). In all, to use launchApplicationWithIdentifier:suspended, I should package my application into a deb file to install it as system application (like Phone, Messages) to grant it root property. Then include this method at where you want to use it and just call it.Portuna
@wyp, Thanks for catching that. It's a little different when you're trying to use private methods within classes that are in the public API (e.g. UIApplication), as opposed to classes that are completely private. I updated my answer to (1) above to show how you can use the private UIApplication method.Middlebrow

© 2022 - 2024 — McMap. All rights reserved.