Eddie
Eddie

Reputation: 323

How to use private APIs to set iOS wallpapers directly. ( Need help updating code to iOS 10, it's already working in iOS 9.3 )

Yes, I'm aware that Apple will reject any code using private APIs. This is for a personal project only. The code has been working fine on an iPhone running iOS 9.3. iOS 10 breaks it. It compiles, but does not set the wallpaper anymore. Perhaps some of the key/value pairs have changed? The only info on the APIs found so far are just some header dumps:

https://github.com/CPDigitalDarkroom/iOS9-SpringBoard-Headers/blob/master/System/Library/PrivateFrameworks/PhotoLibrary.framework/PLStaticWallpaperImageViewController.h

https://github.com/JaviSoto/iOS10-Runtime-Headers/blob/master/PrivateFrameworks/PhotoLibrary.framework/PLStaticWallpaperImageViewController.h

The current code that was working on iOS 9.3:

#import <Photos/Photos.h>


@implementation CMFWallpaper  : NSObject

- (void)setImage:(UIImage *)image {


#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"

    // Instantiate the controller.
    id class123 =NSClassFromString(@"PLStaticWallpaperImageViewController");
    id controller = [[class123 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];
    //    [controller _savePhoto];

#pragma clang diagnostic pop

}

@end

Upvotes: 3

Views: 826

Answers (0)

Related Questions