setKeepAliveTimeout:600处理程序:

时间:2013-04-19 17:25:03

标签: ios voip

我正在开发一个简单的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(@" stopsKeepAliveTimeout");从applicationWillEnterForeground:方法执行,但我从未见过NSLog(@" startingKeepAliveTimeout");应用程序最初启动时或从applicationDidEnterBackground执行时:

如何判断keepalive是否正在工作或甚至被调用?

0 个答案:

没有答案