2

I am working on a lockscreen tweak. In my custom lockscreen view, there is a button which yo can use it to lock and open the native phone app. The IDE I'm using is iOSOpenDev.

I had tried those methods:

  1. Url scheme:i do not want the dial display, so abandoned.

  2. SBSLaunchApplicationWithIdentifier. It is the most popular method,like this:

void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) =
   dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
int result = SBSLaunchApplicationWithIdentifier((CFStringRef)bundleId, false);
dlclose(sbServices);

but in the .xm file, the compiler tells me

Cannot initialize a variable of type 'int (*)(CFStringRef, Boolean)' with an rvalue of type 'void *'".

How can i do this? thanks!

Nate
  • 31,017
  • 13
  • 83
  • 207

1 Answers1

2

I'm not sure which compiler you're using that gives you this error ... the Apple LLVM Compiler (4.2 or 5.0) accepts the code you've shown, with no problems.

But, I think, you should just be able to fix that compile error by casting the return value of dlsym() to a (int (*)(CFStringRef, Boolean)):

int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) =
   (int (*)(CFStringRef, Boolean))dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
Nate
  • 31,017
  • 13
  • 83
  • 207
  • I had added those words "(int (*)(CFStringRef, Boolean))",but the iphone would be a zombie,you must force to reboot. – user2822881 Oct 28 '13 at 10:02
  • That cast will fix the compiler error you posted in your question. If your tweak is crashing your device, then that's a separate problem. – Nate Oct 28 '13 at 17:50
  • Should i add the entitlement file for tweak? – user2822881 Oct 29 '13 at 06:43
  • My code like this:%new(v@:) -(void)httpButtonPressed{ int (*openApp)(CFStringRef, Boolean); void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY); openApp= (int(*)(CFStringRef, Boolean))dlsym(sbServices, "SBSLaunchApplicationWithIdentifier"); openApp(CFSTR("com.apple.Preferences"), FALSE); dlclose(sbServices); } – user2822881 Oct 29 '13 at 07:09
  • 1
    Please don't post new questions / code here in comments. First, can you read the code you posted above? I can't. Second, **this** question asked about how to fix a compiler error. I told you how. Please accept this answer by clicking the "V" mark next to the question. If you have additional questions on this project, please post a **new** question. Concerning the entitlement, it depends which app your code is injected into. If the app it runs in (e.g. SpringBoard) already has the entitlement to launch applications, they you don't need to add anything. If not, then you have a problem. – Nate Oct 29 '13 at 07:17
  • Concerning entitlements again, if your code runs without the entitlement, then it simply won't open the app successfully. Not having the entitlement won't cause a **crash**. – Nate Oct 29 '13 at 07:20
  • But i had got this log:"Entitlement com.apple.springboard.launchapplications required to use kern_return_t _SBXXLaunchApplication(...)".Is it mean that i need to codesign the dylib with a entitlement – user2822881 Oct 31 '13 at 02:11
  • @user2822881, I responded to your other question. – Nate Oct 31 '13 at 07:21