0

我正在开发一个简单的 VoIP 应用程序,但无法理解它是如何工作的。这是我的 AppDelegate.m

#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    // Set-up scheduled background check-in.
    [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{
        //do your task
        NSLog(@"startingKeepAliveTimeout");

    }];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Set-up scheduled background check-in.
    [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{
        //do your task
        NSLog(@"startingKeepAliveTimeout");

    }];

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[UIApplication sharedApplication] clearKeepAliveTimeout];
    NSLog(@"stoppingKeepAliveTimeout");
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}

- (void)applicationWillTerminate:(UIApplication *)application
{

}

@end

我在模拟器和连接的设备上看到的问题是,当我启动应用程序时,我看到 NSLog(@"stoppingKeepAliveTimeout"); 从 applicationWillEnterForeground: 方法执行,但我从未看到 NSLog(@"startingKeepAliveTimeout"); 当应用程序最初启动或从 applicationDidEnterBackground 执行时:

我如何判断 keepalive 是否真的在工作甚至被调用?

4

0 回答 0