Nativescript imagepicker未在iOS中工作::未拾取图像路径?
我将Nativescript与Angular一起使用,并有一个页面,在该页面中,我可以从gallery中拍摄收据或添加内容,并添加一些文本输入,然后发送到服务器 “从库添加”在安卓系统中运行良好,但在iOS系统中则不行 以下是模板代码:Nativescript imagepicker未在iOS中工作::未拾取图像路径?,nativescript,angular2-nativescript,imagepicker,Nativescript,Angular2 Nativescript,Imagepicker,我将Nativescript与Angular一起使用,并有一个页面,在该页面中,我可以从gallery中拍摄收据或添加内容,并添加一些文本输入,然后发送到服务器 “从库添加”在安卓系统中运行良好,但在iOS系统中则不行 以下是模板代码: <Image *ngIf="imageSrc" [src]="imageSrc" [width]="previewSize" [height]="previewSize" stretch="aspectFit"></Image> <
<Image *ngIf="imageSrc" [src]="imageSrc" [width]="previewSize" [height]="previewSize" stretch="aspectFit"></Image>
<Button text="Pick from Gallery" (tap)="onSelectGalleryTap()" class="btn-outline btn-photo"> </Button>
我在下面发布了该行的Android和iOS屏幕截图:
alert("Selection done: " + JSON.stringify(selection));
在Android中,有一个指向文件系统中图像位置的路径,但在iOS中,只有空的花括号,我希望在其中看到路径,然后在提交时,返回的消息是“无法保存图像”,尽管图像预览显示在图像页面上
以下是截图:
安卓:
iOS:
你知道为什么iOS会失败吗
谢谢
==========
使现代化
我现在正在将图像保存到临时位置,但它在iOS中仍然无法工作。它在安卓系统中工作
这是我的代码
import { ImageAsset } from 'tns-core-modules/image-asset';
import { ImageSource, fromAsset, fromFile } from 'tns-core-modules/image-source';
import * as fileSystem from "tns-core-modules/file-system";
...
...
public onSelectGalleryTap() {
alert("in onSelectGalleryTap");
var milliseconds=(new Date).getTime();
let context = imagepicker.create({
mode: "single"
});
let that = this;
context
.authorize()
.then(() => {
that.imageAssets = [];
that.previewSrc = null;
that.imageSrc = null;
return context.present();
})
.then((selection) => {
that.imageSrc = selection.length > 0 ? selection[0] : null;
// convert ImageAsset to ImageSource
fromAsset(that.imageSrc)
.then(res => {
var myImageSource = res;
let folder=fileSystem.knownFolders.documents();
var path=fileSystem.path.join(folder.path, milliseconds+".jpg");
var saved=myImageSource.saveToFile(path, "jpg");
that.previewSrc=path;
const imageFromLocalFile: ImageSource = <ImageSource> fromFile(path);
var base64 = imageFromLocalFile.toBase64String("jpeg", 20);
this.expense.receipt_data=base64;
})
that.cameraImage=null;
that.imageAssets = selection;
that.galleryProvided=true;
// set the images to be loaded from the assets with optimal sizes (optimize memory usage)
selection.forEach(function (element) {
element.options.width = that.previewSize;
element.options.height = that.previewSize;
});
}).catch(function (e) {
console.log(e);
});
}
从“tns核心模块/图像资产”导入{ImageAsset};
从“tns核心模块/图像源”导入{ImageSource、fromAsset、fromFile};
从“tns核心模块/文件系统”导入*作为文件系统;
...
...
公共选举事务处{
警报(“在onSelectGalleryTap中”);
var毫秒=(新日期).getTime();
让context=imagepicker.create({
模式:“单一”
});
让那=这;
上下文
.authorize()
.然后(()=>{
即:imageAssets=[];
that.previewSrc=null;
that.imageSrc=null;
返回context.present();
})
。然后((选择)=>{
that.imageSrc=selection.length>0?selection[0]:null;
//将ImageAsset转换为ImageSource
fromAsset(that.imageSrc)
。然后(res=>{
var myImageSource=res;
让folder=fileSystem.knownFolders.documents();
var path=fileSystem.path.join(folder.path,毫秒+“.jpg”);
var saved=myImageSource.saveToFile(路径,“jpg”);
previewSrc=path;
const imageFromLocalFile:ImageSource=fromFile(路径);
var base64=imageFromLocalFile.toBase64String(“jpeg”,20);
此.expense.receipt_data=base64;
})
cameraImage=null;
即.imageAssets=选择;
galleryProvided=true;
//设置要从具有最佳大小的资产加载的图像(优化内存使用)
selection.forEach(函数(元素){
element.options.width=that.previewSize;
element.options.height=that.previewSize;
});
}).catch(函数(e){
控制台日志(e);
});
}
有什么想法吗?谢谢。这是一个已经沟通的问题,我们中的一些人订阅了,请点击此处查看
更新。这实际上不是问题,iOS在这里的工作方式完全不同。它不返回到原始图像的路径,只返回PHAsset实例。如果以后要通过路径访问图像,则必须将图像写入本地文件夹。@Manoj图像预览将显示在表单中。我们只是想将它从本地存储发送到服务器?图像预览显示它来自Phaset,您可以查看源代码。图像视图可以使用图像资源,该资源在iOS中不保存图像的原始路径,而只保存二进制数据。您必须将数据写入应用程序的存储器中才能创建文件路径。我错过了。你认为这个问题可能很快得到解决吗?我希望如此,但我不太相信它会很快得到解决,因为它已经发布一个月了,而且还没有任何投稿人回复。
import { ImageAsset } from 'tns-core-modules/image-asset';
import { ImageSource, fromAsset, fromFile } from 'tns-core-modules/image-source';
import * as fileSystem from "tns-core-modules/file-system";
...
...
public onSelectGalleryTap() {
alert("in onSelectGalleryTap");
var milliseconds=(new Date).getTime();
let context = imagepicker.create({
mode: "single"
});
let that = this;
context
.authorize()
.then(() => {
that.imageAssets = [];
that.previewSrc = null;
that.imageSrc = null;
return context.present();
})
.then((selection) => {
that.imageSrc = selection.length > 0 ? selection[0] : null;
// convert ImageAsset to ImageSource
fromAsset(that.imageSrc)
.then(res => {
var myImageSource = res;
let folder=fileSystem.knownFolders.documents();
var path=fileSystem.path.join(folder.path, milliseconds+".jpg");
var saved=myImageSource.saveToFile(path, "jpg");
that.previewSrc=path;
const imageFromLocalFile: ImageSource = <ImageSource> fromFile(path);
var base64 = imageFromLocalFile.toBase64String("jpeg", 20);
this.expense.receipt_data=base64;
})
that.cameraImage=null;
that.imageAssets = selection;
that.galleryProvided=true;
// set the images to be loaded from the assets with optimal sizes (optimize memory usage)
selection.forEach(function (element) {
element.options.width = that.previewSize;
element.options.height = that.previewSize;
});
}).catch(function (e) {
console.log(e);
});
}