簡體   English   中英

iOS訪問照片的權限在設備上不起作用

[英]iOS Permission for Accessing Photos not working on device

我想將圖像保存到ios相機膠卷中。 它在模擬器中效果很好。

但是在實際的iPhone上,我沒有這樣的權限提示:

 -  圖片  -

- (void)saveImageToCameraRoll:(CDVInvokedUrlCommand*)command
{
    CDVPluginResult* pluginResult = nil;

    NSString *filename = [command argumentAtIndex:0];
    NSString *tmpFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename]];


    UIImage *image = nil;
    image = [UIImage imageWithContentsOfFile:tmpFile];


    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

    if(status != ALAuthorizationStatusAuthorized || image == nil){
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"noaccess"];
    }
    else{
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"saved"];
    }

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

有什么辦法強迫它嗎?

謝謝。 干杯。

如果拒絕該權限,則無法通過強制獲得提示。 您可以檢查是否可以訪問。 如果您沒有訪問權限,則可以要求用戶針對您的應用在設置應用中授予權限。

像這樣。

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

if (status != ALAuthorizationStatusAuthorized) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Please give this app permission to access your photo library in your settings app!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
    [alert show];
}

iOS僅請求一次許可。 即使您重新安裝該應用程序,也不會再次詢問該權限,它只會使用舊的首選項。

要強制iOS尋求許可,請卸載您的應用程序並更改前幾天的日期,然后重新安裝。 您將再次看到安全提示。

一旦用戶為其授予權限,除非再次卸載並安裝,否則iOS下次不會再次請求相同的權限。

或者,如果要檢查權限,請轉到設置,然后查看您的應用是否已啟用“照片”的權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM