iOS Question screenshot to Album

madru

Active Member
Licensed User
Longtime User
Hi Guys,

I need some help. I try to grab the whole iOS screen and save the picture to the Album

I use the OBJC code Erel has provided:

B4X:
#PlistExtra:<key>NSPhotoLibraryUsageDescription</key><string>This app requires access to the photo library.</string>

Dim no As NativeObject = Me
Dim bmp As Bitmap = no.RunMethod("TakeScreenshot", Null)
Log(bmp)
phone.AddImageToAlbum(bmp)


#If OBJC
- (UIImage*) TakeScreenshot {
    UIView *view = [[UIApplication sharedApplication] keyWindow];
  float scale = [[UIScreen mainScreen] scale];
  CGRect bounds = [[UIApplication sharedApplication] keyWindow].rootViewController.view.bounds;
  BOOL shouldRotate = ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0f && bounds.size.width >= bounds.size.height);
  CGSize size = shouldRotate ? CGSizeMake(view.bounds.size.height, view.bounds.size.width) : view.bounds.size;

  UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  CGContextRef ref = UIGraphicsGetCurrentContext();
  UIBezierPath *path = [UIBezierPath bezierPathWithRect:bounds];
  [[UIColor whiteColor] setFill];
  [path fillWithBlendMode:kCGBlendModeNormal alpha:1];
  if (shouldRotate) {

  CGContextConcatCTM(ref, CGAffineTransformMakeRotation((CGFloat) -M_PI_2));
  CGContextConcatCTM(ref, CGAffineTransformMakeTranslation(-size.height, 0));
  }
  [view drawViewHierarchyInRect:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height) afterScreenUpdates:false];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return image;
}
#End If

but I get this error

Application_Start
359.5851
359.5851
Application_Active
<B4IBitmap: <UIImage: 0x28302c310>, {375, 667}>
SignalHandler 6
Error occurred on line: 92 (Main)
Signal - 6
Stack Trace: (
"0 RFLocation SignalHandler + 120",
"1 libsystem_platform.dylib 0x00000001a5746a10 <redacted> + 40",
"2 libsystem_kernel.dylib 0x00000001a56c9838 <redacted> + 100",
"3 libsystem_kernel.dylib 0x00000001a56c9868 fcntl + 0",
"4 TCC <redacted> + 0",
"5 TCC <redacted> + 0",
"6 TCC <redacted> + 276",
"7 libxpc.dylib <redacted> + 60",
"8 libxpc.dylib <redacted> + 88",
"9 libdispatch.dylib <redacted> + 16"
)
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
as you can see in the logs, it's no objc problem.
Since iOS 11 you need to add the following PlistExtra when adding images to the photo library:
B4X:
#PlistExtra:<key>NSPhotoLibraryAddUsageDescription</key><string>This app add photos to the photo library</string>

Jan
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
yes, I missed that one

THX

NSPhotoLibraryAddUsageDescription: If you want to save a photo/image to your Photo Library. For iOS11 and +
NSPhotoLibraryUsageDescription: If you want to access your Photo Library. For iOS10 and +
 
Upvote 0
Top