0

我想检查我的相机是否已连接,但我似乎无法让它工作。我添加了可达性 .h 和 .m。感谢您对我的学校项目的所有帮助!

- (void)viewDidAppear:(BOOL)animated {

Reachability *reachabilityForCam = [Reachability reachabilityWithAddress:struct sockaddr_in callAddress; 
                                     callAddress.sin_len = sizeof(callAddress); 
                                     callAddress.sin_family = AF_INET; 
                                     callAddress.sin_port = htons(80); 
                                     callAddress.sin_addr.s_addr = inet_addr("X.X.X.X")];     
                                     if ([reachabilityForCam currentReachabilityStatus] == NotReachable) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Cam is not reachable" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [alertView show];
    [self dismissModalViewControllerAnimated:YES];
    }
}
4

1 回答 1

1

感谢您为您的学校项目开发 iOS 项目。但是要检查相机是否可用,您应该使用UIImagePickerController类 API 而不是 Rechability。

请检查如下。 if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerSourceTypeCamera]) {}

我希望这能帮到您。

于 2012-08-29T10:27:41.313 回答