ios获取最新一张照片
PHFetchOptions * options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey: @ "creationDate" ascending: NO]];
PHFetchResult * assetsFetchResults = [PHAsset fetchAssetsWithOptions: options];
return [assetsFetchResults firstObject];
我写的 Native.js,似乎有什么不对……
let Photos = plus.ios.importClass("Photos");
let NSSortDescriptor = plus.ios.importClass("NSSortDescriptor");
let sort = new NSSortDescriptor();
plus.ios.invoke(sort, "sortDescriptorWithKey:ascending:", "creationDate", false);
let PHFetchOptions = plus.ios.importClass("PHFetchOptions");
let options = new PHFetchOptions();
options.sortDescriptors = sort;
let PHAsset = plus.ios.importClass("PHAsset");
let asset = new PHAsset();
let PHFetchResult = plus.ios.importClass("PHFetchResult");
let assetsPHFetchResult = new PHFetchResult();
assetsPHFetchResult = plus.ios.invoke(asset, "fetchAssetsWithOptions:", options);
assetsPHFetchResult.firstObject()
错误提示:undefined is not an object (evaluating 'r.firstObject')
1 个回复
DCloud_iOS_XHY
建议你写个原生插件来实现,native.js 只适用于简单的api调用,复杂点的出问题无法排查