【发布时间】:2016-01-14 00:52:41
【问题描述】:
在我的 tvOS 游戏中,当我触发系统弹出窗口(即按住“HOME”以显示“SLEEP/CANCEL”弹出窗口或应用内购买确认提示)时,不会调用 applicationWillResignActive/applicationDidBecomeActive 函数。
但是,当我暂停/恢复应用程序(即按住“菜单”按钮,多任务处理)时,它们被正确调用,但在显示这些弹出窗口时却没有。
这对我来说是个问题,因为我需要在显示这些弹出窗口时暂停我的游戏。
我有什么遗漏吗?有什么方法可以确定这些弹出窗口何时在 tvOS 上显示?
- 我查看了一些示例应用程序 (DemoBots),它具有相同的行为。
- 将代码作为 iOS 应用程序运行时,它可以正常工作
- Apple TV App Store 上的游戏可以正常运行。
代码很简单
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
和
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"applicationWillResignActive");
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"applicationDidEnterBackground");
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"applicationWillEnterForeground");
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"applicationDidBecomeActive");
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"applicationWillTerminate");
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
【问题讨论】:
-
您好,欢迎来到 SO。请添加代码的重要部分。阅读 how to ask 和 mcve 以了解更受欢迎的问题。
标签: tvos