gpt4 book ai didi

ios - SKStoreProductViewController 取消按钮崩溃或不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:08:00 25 4
gpt4 key购买 nike

我已经为 SKStoreProductViewController 实现了一个委托(delegate)。我将该 View Controller 添加到关键窗口的 View Controller 中。我还在委托(delegate)函数中实现了关闭 View Controller 代码。

问题似乎是这个问题的答案。
Modal App Store won't dismiss
然而,这个问题仍然存在于我的情况中。

显示功能

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
NSString *appURL = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/%@/app/id%@",
[[NSLocale preferredLanguages] objectAtIndex:0], applicationID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];

} else {
NSDictionary* dict = [NSDictionary dictionaryWithObject:applicationID forKey:SKStoreProductParameterITunesItemIdentifier];
SKStoreProductViewController *viewCont = [[SKStoreProductViewController alloc] init];
viewCont.delegate = self;
[viewCont loadProductWithParameters:dict completionBlock:^(BOOL result, NSError *error)
{
UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
if (viewController)
{ [viewController presentViewController:viewCont animated:YES completion:nil]; }
}];
}

委托(delegate)函数

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
if (viewController)
{ [viewController dismissViewControllerAnimated:YES completion:nil]; }
}

最佳答案

问题是你必须实现

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
if (viewController)
{ [self dismissViewControllerAnimated:YES completion:nil]; }
}

在委托(delegate)类中。如果您在委托(delegate)呈现 SKStoreProductViewController 的类中实现它,它将无法工作,因为 SKStoreProductViewController 将尝试在其委托(delegate)中调用 productViewControllerDidFinish: ,它没有实现该方法。

举个例子:

@implementation MainViewController

- (void)presentSecondViewController
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[secondViewController setDelegate:self];
[self presentViewController:secondViewController animated:YES completion:nil];
}

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
if (viewController)
{ [self dismissViewControllerAnimated:YES completion:nil]; }
}

@end


@implementation SecondViewController {
id delegate <SKStoreProductViewControllerDelegate>;
}

- (void)setDelegate:(id)delegate
{
_delegate = delegate;
}

- (void)callStoreProductViewController
{
SKStoreProductViewController *viewCont = [[SKStoreProductViewController alloc] init];
viewCont.delegate = _delegate;
[viewCont loadProductWithParameters:dict completionBlock:^(BOOL result, NSError *error)
{
UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
if (viewController)
{ [_delegate presentViewController:viewCont animated:YES completion:nil]; }
}];
}
@end

所以,如果我确实很好地理解了你的问题,你必须在你的 viewController 类中实现 productViewControllerDidFinish:,因为它是 presentig 的 SKStoreProductViewController

希望这对您有所帮助!

关于ios - SKStoreProductViewController 取消按钮崩溃或不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19262496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com