我在尝试使用相机时遇到了一些问题.问题是有些设备会在设置下显示Camera条目,而其他设备则不会.在那些没有出现Camera开关的设备中,我无法使用相机,因为它没有权限,并且它也不会出现在设置下以启用它们.
这是它在有效设备上的外观:
这就是它在不起作用的设备中的外观.
当我拍摄这些截图时,应用程序应该已经要求权限,但事实并非如此.
我还验证了这些设备没有启用限制.
有任何想法吗?
更新1:添加了代码
这是我用来显示相机的代码(它在自定义视图下,而不是本机相机视图控制器)
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if(videoInput)
{
[self.captureSession addInput:videoInput];
}
else
{
NSLog(@"Error: %@", error);
}
AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self
queue:dispatch_get_main_queue()];
[metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeQRCode]];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
previewLayer.frame = self.view.layer.bounds;
UIView * previewView = [[UIView alloc] initWithFrame:self.view.frame];
[previewView.layer addSublayer:previewLayer];
[self.view addSubview:previewView];
[self.view sendSubviewToBack:previewView];
[self.captureSession startRunning];
Run Code Online (Sandbox Code Playgroud) 我正在开发一个必须使用 WCSession 向 Apple Watch 应用程序发送更新的 iOS 应用程序。它在 iOS/Watch 模拟器中完美运行,但在真实设备中却无法运行。
当我尝试使用sendMessage:replyHandler:errorHandler:方法发送消息时,如果 Apple Watch 应用程序在后台,我会收到以下错误:
[WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] B322D88E-8F50-4BAB-86FF-AFD3B851E1CC errorHandler: NO with WCErrorCodeMessageReplyFailed -> WCErrorCodeNotReachable
但在我的代码中,我添加了各种检查:
if (_session &&
_session.isPaired &&
_session.isWatchAppInstalled &&
_session.isReachable &&
_session.activationState == WCSessionActivationStateActivated)
{
[_session sendMessage:dictionary
replyHandler:nil
errorHandler:^(NSError * _Nonnull error) {
NSLog(@"%@",error);
}
];
}
else
{
[_session transferUserInfo:dictionary];
}
Run Code Online (Sandbox Code Playgroud)
是否有任何原因可以在发送消息时收到“无法访问”错误消息,但session.isReachable返回true?
我还处理了无法访问会话的情况,并且我正在将消息排入队列transferUserInfo:,但由于会话被检测为可访问,因此消息会立即发送,因此它丢失了。