无法通过React Native解除呈现的视图控制器

时间:2018-01-23 09:57:56

标签: ios objective-c swift reactjs react-native

我正在做一个react-native的混合实现。我像这样呈现React View Controller:

    //Identity server
    if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"]))
    {
        IdentityServerRegistrar.Register(services, _appConfiguration);

        //BHARAT : JWT Authentication Middleware
        services.AddAuthentication().AddIdentityServerAuthentication("IdentityBearer", options =>
        {
            options.Authority = _appConfiguration["App:ServerRootAddress"];
            options.RequireHttpsMetadata = false;
            options.ApiName = "default-api";
            options.ApiSecret = "def2edf7-5d42-4edc-a84a-30136c340e13".Sha256();
            options.CacheDuration = TimeSpan.FromMinutes(30);
            options.SaveToken = true;
        });
    }

在react-native页面上的一个动作上,我需要通过导出的方法关闭我提供的这个视图控制器。我试着这样做:

self.vc = [[ContactForm alloc] init];
self.vc.modalPresentationStyle = UIModalPresentationFullScreen;
UIViewController *root = [[[UIApplication sharedApplication] delegate] window].rootViewController;
[root presentViewController:self.vc animated:YES completion:nil];

它没有被解雇,视图控制器保持不变。我添加了@objc(dismissContactForm) func dismissContactForm() { DispatchQueue.main.async { self.dismiss(animated: true, completion: nil) } } ,因为当控件返回到本机应用程序时,它会通过后台线程来实现。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

发现问题。使用React Native' NativeModules,每次调用时都会创建一个新的类实例。目前,我已经使用窗口的根视图控制器来呈现和关闭视图控制器以获取所呈现的控制器的实例,但也可以使用回调块RCTResponseSenderBlock