title: Change iOS Home Screen Wallpaper Programmatically
body: <p>I'm trying to change the wallpaper of Home Screen and Lock Screen programmatically. I've seen many blogs and posts so far like: </p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/6752202/setting-ios-background-lockscreen-image-programatically">Setting iOS background/lockscreen image programatically?</a></li>
  <li><a href="https://www.reddit.com/r/jailbreakdevelopers/comments/24uyr6/which_private_framework_and_methods_set/" rel="nofollow noreferrer">https://www.reddit.com/r/jailbreakdevelopers/comments/24uyr6/which_private_framework_and_methods_set/</a></li>
  <li><a href="https://stackoverflow.com/questions/24696884/cropping-zooming-not-working-while-setting-ios-wallpaper-using-photolibrary-priv">Cropping/zooming not working while setting iOS Wallpaper using PhotoLibrary private framework</a></li>
  <li><a href="https://stackoverflow.com/questions/37000053/handling-private-frameworks-in-xcode-%E2%89%A5-7-3/37001091#37001091">Handling private frameworks in Xcode ≥ 7.3</a></li>
  <li><a href="https://stackoverflow.com/questions/4476777/how-to-set-lock-screen-wallpaper-and-ringtone-programmatically-in-iphone">How to set lock screen , wallpaper and Ringtone programmatically in iPhone?</a></li>
  </ol>
  
  <p>Nothing is working from all of the above. Here is what I tried so far:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>I know that Apple will not approve it but I don't care.</p>
  
  <p>Any help is appreciated. </p>