Closed itsmerockingagain closed 2 years ago
for iOS you have to manage the file by yourself:
const tempFolderPath = knownFolders.temp().getFolder('imagepicker').path;
return new Promise((resolve, reject) => {
let options = PHImageRequestOptions.new();
options.isSynchronous = false;
options.isNetworkAccessAllowed = true;
options.version = PHImageRequestOptionsVersion.Current;
options.resizeMode = PHImageRequestOptionsResizeMode.exact;
options.deliveryMode = PHImageRequestOptionsDeliveryMode.Opportunistic;
PHImageManager
.defaultManager()
.requestImageForAssetTargetSizeContentModeOptionsResultHandler(
asset.ios
, PHImageManagerMaximumSize
, PHImageContentMode.AspectFit
, options
, (uiImage, info) => {
try {
if (!uiImage) {
throw info
.objectForKey(PHImageErrorKey)
.localizedDescription;
}
let tempFilePath = path.join(tempFolderPath, `${Date.now()}-ios.jpg`);
UIImageJPEGRepresentation(uiImage, 1)
.writeToFileAtomically(tempFilePath, true);
resolve(tempFilePath);
}
catch (e) {
reject(e);
}
}
);
});
this code creates a jpg
of the ios image asset inside app's imagepicker
folder to upload it with @nativescript/background-http
.
@wendt88 wendt88 Can you please help me like where to write this code at which step please. camera capture is not returning image asset. If you can help me with some playground , then it will be very helpfull
in my example the variable asset
is the result the takePicture()
method, for android you can easily use asset.android
, wich is the a string (filepath). asset.ios
is a image asset and with my example you can get a filepath.
import camera from '@nativescript/camera';
camera.requestPermissions()
.then(() => camera.takePicture())
.then((asset) => {
return asset.android || .../* my code here to return the promise */
})
.then((filePath) => ...)
@wendt88 problem is asset.ios is empty string for me, i am using NS6 and nativescript-camera plugin
@wendt88 It worked,Thanks so much.
Which platform(s) does your issue occur on?
tns version 6.8.0 tns ios version 6.5.4
"nativescript-camera": "^4.5.0",
Please, tell us how to recreate the issue in as much detail as possible.
Describe the steps to reproduce it.
var options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: true }; camera.takePicture(options)
.then(function (imageAsset) { console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height); console.log("keepAspectRatio: " + imageAsset.options.keepAspectRatio); console.log("Photo saved in Photos/Gallery for Android or in Camera Roll for iOS"); }).catch(function (err) { console.log("Error -> " + err.message); });
this method returns imageAsset without any url or path of the image.
{"_observers":{},"_options":{"width":300,"height":300,"keepAspectRatio":false},"_nativeImage":{}}