Screen capture not working anymore on iOS11


#1

I had my screen capture code working fine till I moved to iOS11 (using the old Screenshot plugin) - user clicks SHARE button, an image is captured (here is where my problem occurs), then the Social Share plugin (from TJ Van Toll) sends it to Facebook (or any other external app).

Like I said, before iOS11 update, everything worked fine. Now, the image is not generated, reason why the app crashes when the button is pressed (everything works fine if I change the code and force to use an image from the resources folder).

I am assuming there are changes in iOS and/or {N} APIs (but I couldn’t find anything/anywhere).

SCREENSHOT PLUGIN

var imageSource = require("image-source");
 
exports.getImage = function(view) {
    if (view.ios) {
        UIGraphicsBeginImageContextWithOptions(view.ios.frame.size, false, 0);
        view.ios.drawViewHierarchyInRectAfterScreenUpdates(CGRectMake(0, 0, view.ios.frame.size.width, view.ios.frame.size.height), true);
        var imageFromCurrentImageContext = UIGraphicsGetImageFromCurrentImageContext();
        console.log("Image returned: "+imageFromCurrentImageContext)
        UIGraphicsEndImageContext();
        return imageSource.fromData(UIImagePNGRepresentation(imageFromCurrentImageContext));
        
    } else if (view.android) {
        view.android.setDrawingCacheEnabled(true);
        var bmp = android.graphics.Bitmap.createBitmap(view.android.getDrawingCache());
        view.android.setDrawingCacheEnabled(false);
        var source = new imageSource.ImageSource();
        source.setNativeSource(bmp);
        return source;
    }
    return undefined;
}

SOCIAL SHARE PLUGIN

var frameModule = require("ui/frame");
var utilsModule = require("utils/utils");
 
function share(thingsToShare, index) {
                var activityController = UIActivityViewController.alloc()
                                .initWithActivityItemsApplicationActivities(thingsToShare, null);
                var presentViewController = activityController.popoverPresentationController;
                if (presentViewController) {
                                var page = frameModule.topmost().currentPage;
                                if (page && page.ios.navigationItem.rightBarButtonItems &&
                                                page.ios.navigationItem.rightBarButtonItems.count > 0) {
                                                presentViewController.barButtonItem = page.ios.navigationItem.rightBarButtonItems[0];
                                } else {
                                                presentViewController.sourceView = page.ios.view;
                                }
                }
 
                utilsModule.ios.getter(UIApplication, UIApplication.sharedApplication)
                                .keyWindow
                                .rootViewController
                                .presentViewControllerAnimatedCompletion(activityController, true, null);
}
 
module.exports = {
                shareImage: function(image) {
                                share([image]);
                },
                shareText: function(text) {
                                share([text]);
                },
                shareUrl: function(url, text) {
                                share([NSURL.URLWithString(url), text]);
                }
};

MY CODE

//Screenshot
var image = require("ui/image");
var plugin = require("nativescript-screenshot");
var fs = require("file-system");
 
//Share plugin
var SocialShare = require("nativescript-social-share");
var imageSourceModule = require("image-source")
 
exports.onShare = function(args) {
 
    //take screenshot
    var img = new image.Image();
    img.imageSource = plugin.getImage(args.object.page.getViewById("printMe"));
 
    var folder = fs.knownFolders.documents().path;
    var d = new Date();
    var day = d.getDate()
    var month = d.getMonth() + 1
    var fileName = "Test"+day+"_"+month+".png"
 
    var path = fs.path.join(folder, fileName);
 
    var image2 = imageSourceModule.fromFile(path);
 
    SocialShare.shareImage(image2, "PPG Finder");
 
}

Any ideas on how to address/fix it? I can’t update my app because it will break a functionality that works on versions prior to iOS11.

Thanks!

By the way, this is the crash error from the console:
Oct 2 13:23:44 Alexs-MacBook-Pro-2 com.apple.CoreSimulator.SimDevice.C5159F6D-9F71-4E71-B6AE-F238E0A9C221[31362] (UIKitApplication:com.asouza.ppgFinder[0xd554][31388][39902]): Service exited due to signal: Segmentation fault: 11 sent by exc handler[0]
Oct 2 13:28:26 Alexs-MacBook-Pro-2 diagnosticd[34560]: dispatch_io_write error: 32 (Broken pipe)
Oct 2 13:28:26 Alexs-MacBook-Pro-2 diagnosticd[34560]: reflect channel created for fd 5
Oct 2 13:28:46 Alexs-MacBook-Pro-2 budd[39961]: objc[39961]: Class BYBuddyDaemonCloudSyncClient is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/SetupAssistant.framework/SetupAssistant (0x10a2af820) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/SetupAssistant.framework/budd (0x109d981f8). One of the two will be used. Which one is undefined.