Monday 5 August 2013

Getting the homescreen and lockscreen wallpaper programatically (iOS)

Here's a small method that will return the homescreen or lock screen wallpaper of an iOS device as an UIImage.

#import <SpringBoard/SBWallpaperView>
#import <objc/runtime.h>

-(UIImage*)wallpaper:(int)var {

        SBWallpaperView *view = [[objc_getClass("SBWallpaperView") alloc] initWithOrientation:UIImageOrientationUp variant:var];
        UIImage *img = [[view.image copy] autorelease];
        [view release];
        return img;

}

Pass 0 for the lockscreen wallpaper, and 1 for the homescreen; feel free to change the orientation as necessary. Enjoy!

No comments:

Post a Comment