需要帮忙。带有地址的Apple的Reachability类不起作用

时间:2012-08-29 09:05:15

标签: iphone xcode networking ip-address reachability

我想检查一下我的相机是否已连接,但我似乎无法让它工作。 我添加了Reachability .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];
    }
}

1 个答案:

答案 0 :(得分:1)

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

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

我希望这会对你有所帮助。