【问题标题】:iOS Permission for Accessing Photos not working on deviceiOS 访问照片的权限在设备上不起作用
【发布时间】:2016-01-26 12:26:24
【问题描述】:

我想将图像保存到 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];
}

有什么办法可以强制吗?

谢谢。干杯。

【问题讨论】:

    标签: ios objective-c permissions photos camera-roll


    【解决方案1】:

    如果您当时拒绝了权限,则无法通过强制获得提示。您可以检查您是否可以访问。如果您没有访问权限,则可以要求用户在设置应用程序中针对您的应用程序授予权限..

    像这样。

    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];
    }
    

    【讨论】:

      【解决方案2】:

      iOS 只请求一次权限。即使您重新安装应用程序,也不会再次询问权限,它只会使用旧的偏好。

      要强制 iOS 请求许可,请卸载您的应用程序并提前几天更改日期并重新安装。您将再次看到安全提示。

      【讨论】:

        【解决方案3】:

        一旦用户允许了它的权限,iOS 下次不会再请求相同的权限权限,除非你卸载并重新安装。

        或者,如果您想检查权限,请转到设置并查看您的应用是否打开了照片的权限。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-09-01
          • 2015-06-21
          • 2021-10-18
          • 2018-12-27
          • 1970-01-01
          • 2014-01-09
          • 2018-11-11
          • 1970-01-01
          相关资源
          最近更新 更多