Shah Aree Rozario
Shah Aree Rozario

Reputation: 11

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

Upvotes: 0

Views: 221

Answers (1)

BornCoder
BornCoder

Reputation: 1066

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.

Upvotes: 1

Related Questions