Last active
August 29, 2015 14:05
-
-
Save kylehowells/eb380ea9c4221df31a17 to your computer and use it in GitHub Desktop.
How to correctly quit an application on iOS 7 (Correct = the same way the app switcher does)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function signature | |
| void (*KH_BKSTerminateApplicationForReasonAndReportWithDescription)(NSString *app, int a, int b, NSString *description) = NULL; | |
| // Find the Symbol. | |
| if (KH_BKSTerminateApplicationForReasonAndReportWithDescription == NULL) { | |
| // dlopen Handle | |
| void* handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL); | |
| // Load the function to our pointer | |
| KH_BKSTerminateApplicationForReasonAndReportWithDescription = dlsym(handle, "BKSTerminateApplicationForReasonAndReportWithDescription"); | |
| } | |
| // If it all worked call it | |
| if (KH_BKSTerminateApplicationForReasonAndReportWithDescription != NULL) { | |
| KH_BKSTerminateApplicationForReasonAndReportWithDescription([application displayIdentifier], 1, 0, @"killed from app switcher"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Old function | |
| void *(*oldTerminateApplication)(NSString *app, int a, int b, NSString *description); | |
| // New function | |
| void *newTerminateApplication(NSString *app, int a, int b, NSString *description) { | |
| NSLog(@"BKSTerminateApplicationForReasonAndReportWithDescription(%@, %d, %d, %@)", app, a, b, description); | |
| return oldTerminateApplication(app, a, b, description); | |
| } | |
| // Find symbol | |
| void *handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL); | |
| void *bskTerminateApplicationWithReasonReference = dlsym(handle, "BKSTerminateApplicationForReasonAndReportWithDescription"); | |
| // If it worked MSHookFunction it | |
| if (!bskTerminateApplicationWithReasonReference) { | |
| NSLog(@"dlsym FAILED to find BKSTerminateApplicationForReasonAndReportWithDescription"); | |
| } | |
| else { | |
| MSHookFunction(bskTerminateApplicationWithReasonReference, (void *)&newTerminateApplication, (void **)&oldTerminateApplication); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment