简体   繁体   中英

Need help. Apple's Reachability class with address does not work

I want to check if my camera is connected, but I can't seem to get this to work. I have added the Reachability .h and .m. I would appreciate all your help for my school project!

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

I appreciate you are working on iOS project for your school project. But to check if camera is available or not you should use UIImagePickerController class API not Rechability.

Please check like below. if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerSourceTypeCamera]) {}

I hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM