nst / iOS-Runtime-Headers

iOS Objective-C headers as derived from runtime introspection
https://github.com/nst/RuntimeBrowser
7.95k stars 1.61k forks source link

How to set the wallpaper in iOS10? #32

Open 6ag opened 8 years ago

6ag commented 8 years ago

I can use the class PLStaticWallpaperImageViewController on iOS9.x.x. But after the upgrade iOS10 not be able to do so.

6ag commented 8 years ago
- (id)getWallPaperVCWithImage:(UIImage *)image
{
    Class wallPaperClass = NSClassFromString(@"PLStaticWallpaperImageViewController");
    id wallPaperInstance = [[wallPaperClass alloc] performSelector:NSSelectorFromString(@"initWithUIImage:") withObject:image];
    [wallPaperInstance setValue:@(YES) forKeyPath:@"saveWallpaperData"];
    return wallPaperInstance;
}

- (void)saveAndAsScreenPhotoWithImage:(UIImage *)image imageScreen:(UIImageScreen)imageScreen finished:(void (^)(BOOL success))finished
{
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        if (PHAuthorizationStatusAuthorized == status) {

            // 保存需要设置为壁纸的图片到相册
            UIImageWriteToSavedPhotosAlbum(image, nil,nil, NULL);

            // 获取壁纸控制器
            id wallPaperVc = [self getWallPaperVCWithImage:image];

            if (wallPaperVc) {
                switch (imageScreen) {
                    case UIImageScreenHome:
                    {
                        if (self.on) {
                            [wallPaperVc performSelector:NSSelectorFromString(@"setImageAsHomeScreenClicked:") withObject:image];
                        }
                    }
                        break;
                    case UIImageScreenLock:
                    {
                        if (self.on) {
                            [wallPaperVc performSelector:NSSelectorFromString(@"setImageAsLockScreenClicked:") withObject:image];
                        }
                    }
                        break;
                    case UIImageScreenBoth:
                    {
                        if (self.on) {
                            [wallPaperVc performSelector:NSSelectorFromString(@"setImageAsHomeScreenAndLockScreenClicked:") withObject:image];
                        }
                    }
                        break;
                    default:
                        break;
                }
                finished(YES);
            } else {
                finished(NO);
            }
        } else {
            // 无权限
            finished(NO);
        }
    }];
}

Can you help me?

makleso6 commented 7 years ago

+1

MTJailed commented 6 years ago

Apple now requires the SpringBoard or Photos entitlement for updating the wallpaper. Therefore it is impossible to do this even with private api’s.

meetiosdev commented 5 years ago

i am unable to add file PLStaticWallpaperImageViewController. When i add by framework it shows linker error please help