OGeek|极客世界-中国程序员成长平台

标题: iOS 7 后台获取 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:02
标题: iOS 7 后台获取

我目前正在开发一个 iOS 应用程序,我在其中使用 [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];。根据我以这种方式实现的文档。

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    NSLog(@"Launched in background %d", UIApplicationStateBackground == application.applicationState);

    [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
    i =0;

    return YES;
}


-(void)applicationUIApplication *)application performFetchWithCompletionHandlervoid (^)(UIBackgroundFetchResult))completionHandler {
    NSLog(@"Fetch started");
    ++i;    

    // Set up Local Notifications
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    NSDate *now = [NSDate date];
    localNotification.fireDate = now;

    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.alertBody = @"BG Mode";
    localNotification.applicationIconBadgeNumber = i;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

    completionHandler(UIBackgroundFetchResultNewData);
    NSLog(@"Fetch completed");
}

我的问题是我尝试调试它以了解此方法调用的频率。我没有得到任何澄清。我已经用 60 秒的时间间隔进行了测试,但这也不起作用。请给我任何想法或建议。提前致谢。



Best Answer-推荐答案


澄清一下,您还根据 Apple 的文档在 Info.plist 中设置了 UIBackgroundModes ...

This property has no effect for apps that do not have the UIBackgroundModes key with the fetch value in its Info.plist file.

关于iOS 7 后台获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21130741/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4