Note that there are some explanatory texts on larger screens.

plurals
  1. POTake a snapshot of a PKAddPassesViewController's view
    primarykey
    data
    text
    <p>I'm trying to take a snapshot of the view displayed when the user is prompted to add a pass.</p> <p>The goal is being able to generate an image from a given pkpass</p> <p>I was hoping something like this could work:</p> <pre><code>NSString *filePath = [[NSBundle mainBundle] pathForResource:@"columbus" ofType:@"pkpass"]; PKPass *pass = [[PKPass alloc] initWithData:[NSData dataWithContentsOfFile:filePath] error:nil]; PKAddPassesViewController *pkAddPassesViewController = [[PKAddPassesViewController alloc] initWithPass:pass]; [self presentViewController:pkAddPassesViewController animated:YES completion:^(){ UIImage *image = [pkAddPassesViewController.view captureView]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; [self.view addSubview:imageView]; }]; </code></pre> <p>With captureView being:</p> <pre><code>- (UIImage *)captureView { CGRect screenRect = self.bounds; UIGraphicsBeginImageContext(self.bounds.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor clearColor] set]; CGContextFillRect(ctx, screenRect); [self.layer renderInContext:ctx]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } </code></pre> <p>Guess what? I was wrong:</p> <p>I tried:</p> <ul> <li><p>Using the completion callback and the animationFinished callback</p></li> <li><p>Setting the hidden property</p></li> <li><p>Using a timer to make sure the pass was visible on screen when the screenshot was taken</p></li> <li><p>Taking a snapshot of the parent view</p></li> </ul> <p>I ran out of ideas, so any suggestion is appreciated Thanks in advance</p> <p>Oh, I've uploaded a minimal project here: <a href="https://github.com/framp/demo-capturing-passbook" rel="nofollow">https://github.com/framp/demo-capturing-passbook</a></p> <p>EDIT: I'm able to take a snapshot of other views and I can load other UIImage just fine with the code above. The UIImage which is returned is a blank image</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload