Skip to content

[IOS] snapshotManager.takeSnap() doesn't work #236

@damacchi

Description

@damacchi

Describe the bug
When i use MapboxGL.snapshotManager.takeSnap(options) i get this error:
Error: Could not create snapshot

The error comes from this function in MGLSnapshotModule.m
and there is no script for MGLMapSnapshotter in the repo.

RCT_EXPORT_METHOD(takeSnap:(NSDictionary *)jsOptions
                  resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        MGLMapSnapshotOptions *options = [self _getOptions:jsOptions];
        MGLMapSnapshotter *snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options];
        
        [snapshotter startWithCompletionHandler:^(MGLMapSnapshot *snapshot, NSError *err) {
            if (err != nil) {
                reject(@"takeSnap", @"Could not create snapshot", err);
                return;
            }
            
            NSString *result = nil;
            if ([jsOptions[@"writeToDisk"] boolValue]) {
                result = [RNMBImageUtils createTempFile:snapshot.image];
            } else {
                result = [RNMBImageUtils createBase64:snapshot.image];
            }
            
            resolve(result);
        }];
    });
}

To Reproduce
Just try to take a snapshot with snapshot manager.

Expected behavior
It should return an uri or a base64 file

Versions (please complete the following information):

  • Platfrom: iOS
  • React Native Version 0.59
  • SDK: 7.0.0-rc3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions