Skip to content

Instantly share code, notes, and snippets.

@camdenfullmer
Last active February 18, 2024 03:05
Show Gist options
  • Save camdenfullmer/b287f634acd089f4b92f to your computer and use it in GitHub Desktop.
Save camdenfullmer/b287f634acd089f4b92f to your computer and use it in GitHub Desktop.
Set the wallpaper (lock and/or home screen) on iOS using Apple's private API. Please be aware that including this code in an App Store submission will result in a rejection. This has only been tested on iOS 9.2.
@implementation CMFWallpaper
+ (void)setImage:(UIImage *)image {
NSAssert([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized, @"access to photos is needed to set the wallpaper");
NSString *path;
#if TARGET_OS_SIMULATOR
path = @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibrary.framework";
#else
path = @"/System/Library/PrivateFrameworks/PhotoLibrary.framework";
#endif
NSBundle *bundle = [NSBundle bundleWithPath:path];
[bundle load];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// Instantiate the controller.
id class = NSClassFromString(@"PLStaticWallpaperImageViewController");
id controller = [[class alloc] performSelector:@selector(initWithUIImage:) withObject:image];
// Select what wallpaper mode.
// 0 - Both lock screen and home screen.
// 1 - Home screen only.
// 2 - Lock screen only.
int wallpaperMode = 0;
[controller setValue:@(wallpaperMode) forKey:@"wallpaperMode"];
// Tell the controller to save the data.
[controller setValue:@YES forKey:@"saveWallpaperData"];
// Save the photo.
[controller performSelector:@selector(_savePhoto) withObject:nil];
#pragma clang diagnostic pop
}
@end
@MichaelMKenny
Copy link

Hi MichaelMKenny

Thanks for your detailed reply.

I checked your code and that really works perfectly on ios 13 simulators.

I'm planning to create an app which where I can select/add pictures of a particular category and with in-app in the configuration screen, user can set either set both lock and home screen or any single option and user can set a timer in which app will change wallpaper on regular interval.

I was planning to add a payment option (IAP) to unlock some categories.

As per my knowledge with Jailbroken devices, I can't implement IAP. If I would like to move with this app with jailbreak devices only then can you please guide

  1. What payment options I need to add to unlock some categories?
  2. I can add logic to randomly chose images and call your methods in the background to set wallpaper
  3. Where do I need to publish the app for jailbroken devices?

Please advise and guide to get some insights to get this app done.

--
Regards

I'm sorry I don't think I can be of anymore assistance. My code is just a proof of concept. Hope you find a way to do what you want to do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment