UIAlertView Dismiss返回主屏幕



我的应用程序以一个"主屏幕";导航控制器,位于自己的故事板中,可以分段到不同的故事板,每个故事板都从一个新的导航控制器开始。我的一个次要故事板有一个付费墙。当用户选择在不购买的情况下关闭付费墙时,我所能完成的就是关闭付费墙并显示需要购买的故事板的根视图控制器。我正试图将用户发送回";主屏幕";在那里他们可以看到其他内容或转到不同的故事板。

[PaywallManager registerBlockingPaywallClosedHandler:^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Blocked Paywall Closed" message:@"Return to home screen without purchase." preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[alertController dismissViewControllerAnimated:true completion:^{
}]
}];

[alertController addAction:okAction];
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootViewController presentViewController:alertController animated:true completion:^{}];
}];

当用户按下OK按钮关闭UIAlertView时,我需要返回到主导航控制器(主屏幕(。目前,当用户解除UIAlertView时,他们可以访问付费内容。如果我删除了关闭的处理程序,应用程序就会卡在付费墙上,直到购买或用户杀死应用程序。如有任何帮助,我们将不胜感激。我仍然在为Objective-C而挣扎,还没有时间学习Swift,所以请对我宽容一点。

我想明白了。解决方案在这里:

[PaywallManager registerBlockingPaywallClosedHandler:^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"No Purchase Made" message:@"Return to the Home screen without purchase." preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];

[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}];

最新更新