Created
October 13, 2015 03:39
-
-
Save cfilipov/406873356f814d59ef67 to your computer and use it in GitHub Desktop.
Wake iOS application via SpringBoardServices
This file contains 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
// Inspired [copied] from: http://pastie.org/pastes/4855500#7-8,11-13 | |
#import "WakeHelper.h" | |
#import <mach/mach.h> | |
#import <dlfcn.h> | |
#define SB_SERVICES_PATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices" | |
typedef mach_port_t sig_SBSSpringBoardServerPort(); | |
typedef mach_error_t sig_SBSetApplicationNextWakeDate(mach_port_t sbsPort, double wakeTime, int flags); | |
static sig_SBSetApplicationNextWakeDate *fn_SBSetApplicationNextWakeDate; | |
static sig_SBSSpringBoardServerPort *fn_SBSSpringBoardServerPort; | |
static void *fx_SpringBoardServices; | |
static void loadSpringBoardServices() { | |
if (!fx_SpringBoardServices) { | |
fx_SpringBoardServices = dlopen(SB_SERVICES_PATH, RTLD_LAZY); | |
fn_SBSetApplicationNextWakeDate = (sig_SBSetApplicationNextWakeDate *)dlsym(fx_SpringBoardServices, "SBSetApplicationNextWakeDate"); | |
fn_SBSSpringBoardServerPort = (sig_SBSSpringBoardServerPort *)dlsym(fx_SpringBoardServices, "SBSSpringBoardServerPort"); | |
} | |
} | |
@implementation WakeHelper | |
+ (void)setApplicationNextWakeDate:(NSDate *)date { | |
loadSpringBoardServices(); | |
double wakeDate = [date timeIntervalSinceReferenceDate]; | |
mach_error_t err = fn_SBSetApplicationNextWakeDate(fn_SBSSpringBoardServerPort(), wakeDate, 0); // Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) | |
if (err != 0) { | |
NSLog(@"Could not set wake date: %s", mach_error_string(err)); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment