NativeScript / nativescript-imagepicker

Imagepicker plugin supporting both single and multiple selection.
Apache License 2.0
104 stars 73 forks source link

Fatal crash in iOS: NativeSource() expects UIImage instance. #174

Closed jackwaller closed 6 years ago

jackwaller commented 6 years ago

Hi,

The image picker initial launches and correctly shows the albums page though when selecting an album causes a fatal error within iOS. The android version works as expected.

Package.json { "description": "NativeScript Application", "license": "SEE LICENSE IN ", "readme": "NativeScript Application", "repository": "", "nativescript": { "id": "org.nativescript.session", "tns-android": { "version": "4.0.0-2018.4.4.1" }, "tns-ios": { "version": "4.0.1" } }, "dependencies": { "@angular/animations": "~5.2.0", "@angular/common": "~5.2.0", "@angular/compiler": "~5.2.0", "@angular/core": "~5.2.0", "@angular/forms": "~5.2.0", "@angular/http": "~5.2.0", "@angular/platform-browser": "~5.2.0", "@angular/platform-browser-dynamic": "~5.2.0", "@angular/router": "~5.2.0", "moment": "^2.20.1", "nativescript-angular": "~5.2.0", "nativescript-bitmap-factory": "^1.7.1", "nativescript-cardview": "^2.0.5", "nativescript-checkbox": "^3.0.3", "nativescript-dev-android-snapshot": "0.0.11", "nativescript-dev-webpack": "^0.10.0", "nativescript-imagepicker": "^5.0.2", "nativescript-loading-indicator": "^2.4.0", "nativescript-modal-datetimepicker": "^1.1.0", "nativescript-oauth": "^2.1.2", "nativescript-orientation": "^2.2.0", "nativescript-platform-css": "^1.6.5", "nativescript-pulltorefresh": "^2.1.0", "nativescript-theme-core": "~1.0.4", "nativescript-ui-listview": "^3.5.4", "nativescript-web-image-cache": "^4.2.4", "nativescript-webview-utils": "^2.0.3", "reflect-metadata": "~0.1.10", "rxjs": "~5.5.5", "tns-core-modules": "^4.0.0-2018-04-02-03", "tns-platform-declarations": "^3.4.1", "zone.js": "~0.8.18" }, "devDependencies": { "babel-traverse": "6.26.0", "babel-types": "6.26.0", "babylon": "6.18.0", "lazy": "1.0.11", "nativescript-dev-sass": "^1.3.5", "nativescript-dev-typescript": "^0.6.0", "typescript": "~2.6.2", "webpack": "~3.10.0", "webpack-bundle-analyzer": "^2.9.1", "webpack-sources": "~1.1.0", "clean-webpack-plugin": "~0.1.19", "copy-webpack-plugin": "~4.3.0", "raw-loader": "~0.5.1", "css-loader": "~0.28.7", "nativescript-worker-loader": "~0.8.1", "resolve-url-loader": "~2.2.1", "extract-text-webpack-plugin": "~3.0.2", "uglifyjs-webpack-plugin": "~1.1.6", "@angular/compiler-cli": "~5.2.0", "@ngtools/webpack": "~1.9.4", "sass-loader": "~6.0.6" } }

Error

Fatal JavaScript exception - application has been terminated. Native stack trace: 1 0x10d0da359 NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState, JSC::Exception, bool) 2 0x10d1011fb NativeScript::FFICallback::ffiClosureCallback(ffi_cif, void, void*, void) 3 0x10d9f649e ffi_closure_unix64_inner 4 0x10d9f6de2 ffi_closure_unix64 5 0x10f1ee8b6 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] 6 0x10f1ee78e -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] 7 0x10f1f3d00 -[UICollectionView _updateVisibleCellsNow:] 8 0x10f1f9c21 -[UICollectionView layoutSubviews] 9 0x10e7eda6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 10 0x112add61c -[CALayer layoutSublayers] 11 0x112ae17ad CA::Layer::layout_if_needed(CA::Transaction) 12 0x112a6886c CA::Context::commit_transaction(CA::Transaction) 13 0x112a95946 CA::Transaction::commit() 14 0x10e746167 _afterCACommitHandler 15 0x1124f2c07 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION 16 0x1124f2b5e CFRunLoopDoObservers 17 0x1124d7124 CFRunLoopRun 18 0x1124d6889 CFRunLoopRunSpecific 19 0x11550c9c6 GSEventRunModal 20 0x10e71c5d6 UIApplicationMain 21 0x10d9f6c3d ffi_call_unix64 22 0x13604f790 JavaScript stack trace: 1 setNativeSource@file:///app/tns_modules/tns-core-modules/image-source/image-source.js:112:86 2 fromNativeSource@file:///app/tns_modules/tns-core-modules/image-source/image-source.js:221:32 3 _createImageSourceFromSrc@file:///app/tns_modules/tns-core-modules/ui/image/image-common.js:107:63 4 @file:///app/tns_modules/tns-core-modules/ui/image/image.js:121:39 5 applyAllNativeSetters@file:///app/tns_modules/tns-core-modules/ui/core/properties/properties.js:961:28 6 initNativeView@file:///app/tns_modules/tns-core-modules/ui/core/properties/properties.js:905:30 7 onResumeNativeUpdates@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:627:36 8 _resumeNativeUpdates@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:272:39 9 onLoaded@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:231:34 10 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:311:98 11 callFunctionWithSuper@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:304:13 12 callLoaded@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:311:35 13 loadView@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:439:28 14 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:233:27 15 eachChildView@file:///app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js:125:34 16 eachChild@file:///app/tns_modules/tns-core-modules/ui/core/view/view-common.js:855:27 17 onLoaded@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:232:23 18 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:311:98 19 callFunctionWithSuper@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:304:13 20 callLoaded@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:311:35 21 loadView@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:439:28 22 _addViewCore@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:434:26 23 _addView@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:420:26 24 prepareCell@file:///app/tns_modules/nativescript-ui-listview/ui-listview.js:1651:26 25 listViewCellForItemAtIndexPath@file:///app/tns_modules/nativescript-ui-listview/ui-listview.js:569:26 26 UIApplicationMain@[native code] 27 start@file:///app/tns_modules/tns-core-modules/application/application.js:264:26 28 bootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:86:28 29 bootstrapModule@file:///app/tns_modules/nativescript-angular/platform-common.js:72:26 30 anonymous@file:///app/main.js:16:57 31 evaluate@[native code] 32 moduleEvaluation@[native code] 33 @[native code] 34 promiseReactionJob@[native code] JavaScript error: file:///app/tns_modules/tns-core-modules/image-source/image-source.js:112:86: JS ERROR Error: The method setNativeSource() expects UIImage instance.

jackwaller commented 6 years ago

I can confirm that the plugin works as expected on tns-core-modules 3.4

tbozhikov commented 6 years ago

This is fixed with the latest version of the image picker (6.0.0), made available just now, so feel free to upgrade. Let us know if you have issues with it.

jackwaller commented 6 years ago

Thank you I am testing it out now and it looks awesome! Once I have selected an image though how do I determine what the src is? The old method of selected.fileUri no longer works

tbozhikov commented 6 years ago

The fileUri is no more present because the picker now returns tns-core-modules ImageAsset and it does not support this functionality. Could you share what is you use case of the image picker so that I can try to help you further?

jackwaller commented 6 years ago

Previously I was updating the src of the "placeholder" image to that which the user had just picked. I was achieving this by passing the image instance to the startSelection() function as below.

updateImage(image: Image) {

        let context = imagepicker.create({
            mode: "single", // use "multiple" for multiple selection
        });

        startSelection(context,image);

        // Initialise the image picker
        function startSelection(context,image: Image) {
            context
                .authorize()
                .then(function() {
                    return context.present();
                })
                .then(function(selection) {
                    selection.forEach(function(selected) {
                        // Process the image
                        image.src=selected.fileUri
                    });
                }).catch(function (e) {
                    // process error
                });
        }
    }
tbozhikov commented 6 years ago

Is image an instance of tns-core-modules/ui/image? In this case you can set the image.src = selected, since tns-core-modules/ui/image works just OK with ImageAsset.