سؤال

I have an application that presents a view controller from a framework. In the framework's view controller, I check for a valid license in loadView. A callback is returned to the UI to not load the view if license is not valid. So, now I'm testing for if the user of my SDK tries to not implement the license check. Even though the license is not valid the vie still displays.

I've tried the following code, but the view gets displayed anyway:

- (void)viewWillAppear:(BOOL)animated
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        if (self.validLicense) {
            [self loadCameraPreview];
        } else {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    } else {
        IDLog(@"No Camera!");
        self.tapRecognizer.enabled = NO;
    }
}

Does anybody know how I can kill the view and not display it? This view is in an SDK. It is not in the application. With the above code, the application just gets stuck on this page and does not work. Which I guess is OK. But I'd really like to make the presented view unload.

The presentation code looks like this:

if (bundle) {
    if (!self.cameraVC) {
        self.cameraVC =
            [[IDCameraViewController alloc] initWithNibName:@"IDCameraViewController"
                                                     bundle:bundle];
        [self.cameraVC setOutImageBinarization:NO];
        [self.cameraVC setTapRecognizerEnabled:YES];
        [self.cameraVC setReturnType:BOTH];

    }
    UIView *cameraView = self.cameraVC.view;
    //if (self.validLicense) {
        [self.cameraVC setCaptureMode:self.mode];
        [self.cameraVC willMoveToParentViewController:self];
        [self addChildViewController:self.cameraVC];
        [self.view addSubview:cameraView];
        [self.cameraVC didMoveToParentViewController:self];
    //}

//        if (self.validLicense == NO) {
//            UIAlertView *alert =
//                [[UIAlertView alloc] initWithTitle:@"License Activation"
//                                           message:@"A valid license must be activated for this product."
//                                          delegate:self
//                                 cancelButtonTitle:@"OK"
//                                 otherButtonTitles:nil];
//            [alert show];
//        }
}

Remember, I'm commenting out the check to test if a user of my SDK tries to use it WITHOUT a valid license.

هل كانت مفيدة؟

المحلول

I think it is not possible to close any view controller when loadView method is already called, you will have to wait until the viewDidLoad gets called and then dismiss it or remove it from parentViewController. However, good way will be to decide beforehand whether to present such view controller or not. So, if you check that the person has valid license before presenting the view, that would be much better. But, if you have found out something, then I would surely love to hear it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top