我正在尝试以编程方式更改主屏幕和锁定屏幕的墙纸。到目前为止,我已经看过许多博客和帖子,例如:
以上所有方法均无效。这是我到目前为止尝试过的:
NSString *path;
#if TARGET_OS_SIMULATOR
path = @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/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:@"isWallpaperEdit"];
[controller setValue:@YES forKey:@"saveWallpaperData"];
// Save the photo.
[controller performSelector:@selector(_savePhoto) withObject:nil];
[controller performSelector:@selector(setWallpaperForLocations:) withObject:@(wallpaperMode)];
#pragma clang diagnostic pop
我知道Apple不会批准它,但我不在乎。
感谢您的帮助。