以编程方式更改iOS主屏幕墙纸

时间:2018-12-11 11:16:28

标签: ios objective-c iphone ios12 iphone-privateapi

我正在尝试以编程方式更改主屏幕和锁定屏幕的墙纸。到目前为止,我已经看过许多博客和帖子,例如:

  1. Setting iOS background/lockscreen image programatically?
  2. https://www.reddit.com/r/jailbreakdevelopers/comments/24uyr6/which_private_framework_and_methods_set/
  3. Cropping/zooming not working while setting iOS Wallpaper using PhotoLibrary private framework
  4. Handling private frameworks in Xcode ≥ 7.3
  5. How to set lock screen , wallpaper and Ringtone programmatically in iPhone?

以上所有方法均无效。这是我到目前为止尝试过的:

    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不会批准它,但我不在乎。

感谢您的帮助。

0 个答案:

没有答案