Open andreasteffanoni opened 3 years ago
Still stuck with the issue. I had to bypass some code to make the plugin working. Here is my workaround.
if (this._saveToGallery) {
PHPhotoLibrary.sharedPhotoLibrary().performChangesCompletionHandler(function () {
PHAssetChangeRequest.creationRequestForAssetFromImage(imageSourceResult_1.ios);
}, function (success, err) {
/*
if (success) {
var fetchOptions = PHFetchOptions.alloc().init();
var sortDescriptors = NSArray.arrayWithObject(NSSortDescriptor.sortDescriptorWithKeyAscending("creationDate", false));
fetchOptions.sortDescriptors = sortDescriptors;
fetchOptions.predicate = NSPredicate.predicateWithFormatArgumentArray("mediaType = %d", NSArray.arrayWithObject(1));
var fetchResult = PHAsset.fetchAssetsWithOptions(fetchOptions);
if (fetchResult.count > 0) {
var asset = fetchResult[0];
var dateDiff = asset.creationDate.valueOf() - currentDate_1.valueOf();
if (Math.abs(dateDiff) > 1000) {
console.warn("Image asset returned was created more than 1 second ago");
}
imageAsset_1 = new core_1.ImageAsset(asset);
_this.setImageAssetAndCallCallback(imageAsset_1);
}
}
else {
core_1.Trace.write("An error ocurred while saving image to gallery: " +
err, core_1.Trace.categories.Error, core_1.Trace.messageType.error);
}*/
});
}
// else {
imageAsset_1 = new core_1.ImageAsset(imageSourceResult_1.ios);
this.setImageAssetAndCallCallback(imageAsset_1);
// }
This works.
Environment "nativescript": "^7.0.8", "@nativescript/core": "^7.0.7", "@nativescript/ios": "7.0.0", "@nativescript/camera": "^5.0.0",
In a plain JS app, when taking a picture, the iOS version of the app crashes with the message " NativeScriptError: TypeError: Cannot read property 'creationDate' of undefined". The crash happens after taking the photo, when the user confirms the picture. The android version works without issues. The app was working fine before upgrading to NS 7.
To Reproduce
Inspecting the camera plugin code, the error happens in line 54:
Debugging, fetchResult.count is > 0 but asset is undefined (thus the error).