I was trying to capture and save an image of the splash screen inside application:didFinishLaunchingWithOptions:
using the following code:
UIWindow *w = [[[UIApplication sharedApplication] windows] firstObject];
UIGraphicsBeginImageContext(w.bounds.size);
[w.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
time_t unixTime = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *storePath = [NSString stringWithFormat:@"%@/%ld.png", applicationDocumentsDir, unixTime];
[UIImagePNGRepresentation(img) writeToFile:storePath atomically:YES];
However unfortunately the image is saved as a transparent image. It is probably because my UIWindow object is not the right one. Can anybody please direct me into succeeding with that?