您好我正在尝试访问iOS上的用户相册,以便用户在我的应用中选择个人资料照片。
我使用的是本机脚本,我无法弄清楚如何请求权限。我的错误是:
Scrapy
我用过
CONSOLE LOG file:///app/shared/user-view-model/user-view-model.js:96:28: fileUri: file:///var/mobile/Media/DCIM/100APPLE/IMG_0002.JPG
CONSOLE LOG file:///app/shared/user-view-model/user-view-model.js:101:24: NSErrorWrapper: You don’t have permission to save the file “100APPLE” in the folder “DCIM”.
在我的info.plist中,但没有运气。有人知道我错过了什么吗?
<key>NSPhotoLibraryUsageDescription</key>
<string> ${PRODUCT_NAME} photo use</string>
答案 0 :(得分:1)
PHPhotoLibrary.requestAuthorization(function (result) {
if (result === PHAuthorizationStatus.PHAuthorizationStatusAuthorized) {
// OK
} else {
// no permissions!
}
});
您还需要 info.plist
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
</dict>
答案 1 :(得分:0)
我从这个github帖子中找到了一个解决方案
https://github.com/NativeScript/sample-ImageUpload/issues/2#issuecomment-252795778
解决方案是使用getImage()方法,然后在结果上使用saveToFile方法。
private selectImage(context){
context.authorize()
.then(() => {return context.present()})
.then((selection) => {
selection.forEach((selected) => {
selected.getImage()
.then((imageSource) => {
var appPath = fs.knownFolders.currentApp().path;
var profilePath = "/img/profile.jpg";
var filePath = fs.path.join(appPath, profilePath);
var saved = imageSource.saveToFile(filePath, enums.ImageFormat.jpeg);
console.log(`item saved:${saved}`);
console.log("FilePath: " + filePath);
console.log("Image source " + JSON.stringify(imageSource));
},
(error) => {
console.log("error");
})
})
})
}