Skip to content

Instantly share code, notes, and snippets.

@shinvou
Created August 18, 2015 14:33
Show Gist options
  • Save shinvou/e8ca0913415b2a9b04c3 to your computer and use it in GitHub Desktop.
Save shinvou/e8ca0913415b2a9b04c3 to your computer and use it in GitHub Desktop.
Present notifications that keep in notification center
extern "C" CFTypeRef SecTaskCopyValueForEntitlement(void* task, CFStringRef entitlement, CFErrorRef *error);
static void PresentBannerWithMessageForIdentifier(NSString *message, NSString *identifier, NSDictionary *userInfo)
{
UILocalNotification *notification = [objc_getClass("UILocalNotification") new];
[notification setAlertBody:message];
[notification setUserInfo:userInfo];
//[notification setApplicationIconBadgeNumber:0];
[notification setHasAction:YES];
[notification setAlertAction:nil];
[SBSLocalNotificationClient scheduleLocalNotification:notification bundleIdentifier:identifier];
}
CFTypeRef (*original__SecTaskCopyValueForEntitlement)(void *task, CFStringRef entitlement, CFErrorRef *error);
CFTypeRef replaced__SecTaskCopyValueForEntitlement(void *task, CFStringRef entitlement, CFErrorRef *error)
{
CFTypeRef ret = original__SecTaskCopyValueForEntitlement(task, entitlement, error);
NSString *entitlementString = CFBridgingRelease(entitlement);
if ([entitlementString isEqualToString:@"com.apple.localnotification.schedulingproxy"]) {
ret = kCFBooleanTrue;
}
return ret;
}
%ctor {
@autoreleasepool {
if ([[[NSClassFromString(@"NSProcessInfo") processInfo] processName] isEqualToString:@"SpringBoard"]) {
MSHookFunction(MSFindSymbol(NULL, "_SecTaskCopyValueForEntitlement"), (void *)replaced__SecTaskCopyValueForEntitlement, (void **)&original__SecTaskCopyValueForEntitlement);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment