Je suis en train de sauver écran de mon application en utilisant le code suivant:Capture d'écran ne semble pas à l'application Photos (iOS obj-c)
UIView* view = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
NSURL* documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString* filename = [NSString stringWithUTF8String: @"screenshot.png"];
NSString* path =[NSString stringWithFormat:@"%@/%@",[documentsDirectory path], filename];
BOOL saved = [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
NSLog(saved ? @"Saved" : @"Not saved");
Il enregistre Saved
, mais l'image ne semble pas en Photos app.
documentsDirectory
: /var/mobile/Containers/Data/Application/003D7989-D88E-48FF-A3C5-86A340C6F077/Documents
Ce que je fais mal? Merci pour la réponse.
hmm, il est maintenant enregistrez à Photos, mais il est purement image blanche –
bien, peut-être que l '" image "est blanc :) Je vais mettre à jour le code source;) – ddb
Je pense que vous devriez simplement obtenir la vue actuelle de viewController au lieu de "UIView * view = [[[UIApplication sharedApplication] keyWindow] sous-vues] lastObject];" – ddb