AppleTV UIAlertView相当于

时间:2015-10-22 04:54:31

标签: objective-c apple-tv

因此,我正在AppleTV上的SpriteKit游戏中进行应用内购买,但如果付款错误或任何其他各种错误,我想显示错误。 UIAlertView就是我在iOS上的表现,但这并不是tvOS的选择。有类似的东西可以做吗?基本上,我需要弹出描述错误的东西和一个关闭弹出窗口的按钮。添加更多按钮(如UIAlertView)的能力将是锦上添花。

注意:我对此进行了一些研究,大多数事情似乎都指向使用TVML,但是,我不相信这是与SpriteKit混合使用的选项。如果它解释了如何导入TVML(我几乎一无所知)并将其与SpriteKit一起运行,我将接受与此相关的答案。我假设我正在寻找与TVML无关的答案。

1 个答案:

答案 0 :(得分:17)

检查tvOS UIAlertController类:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                           message:@"This is an alert."
                           preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
   handler:^(UIAlertAction * action) {}];

[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

编辑:使用SpriteKit时,最后一行将替换为

UIViewController* controller = [UIApplication sharedApplication].keyWindow.rootViewController;
[controller presentViewController:alert animated:YES completion:nil];

请注意,自iOS 8起,此类也可在iOS中使用!