【发布时间】:2014-03-26 07:04:41
【问题描述】:
我不知道如何实现后台服务。但是在搜索互联网
我看到一些关于ios 7中引入的Background fetch Api的教程。我无法理解实现的过程。Plesae提供一些帮助。`
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
return YES;
}
- (void) application:(UIApplication *)application
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"hai");
[NSTimer scheduledTimerWithTimeInterval:0.30
target:self
selector:@selector(sampleTest)
userInfo:nil
repeats:NO];
completionHandler(UIBackgroundFetchResultNewData);
}
-(void)sampleTest
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"hai" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}
仅在应用程序启动时调用,但之后 30 秒后我看不到任何警报
【问题讨论】:
-
您不会看到警报,这不是后台提取的用途。除非您使用静默推送通知(仅限 iOS 7),否则您无法手动触发后台提取。 iOS 会在需要时调用此方法,您可以在模拟器中通过转到 Xcode > Debug > Simulate background fetch 来模拟它。我怀疑警报是否会显示,因为您的应用不在前台。
-
Xcode > Debug > Simulate background fetch if I do此警报仅在模拟器启动时出现,但在处于活动状态时我看不到
-
应用激活时不会出现。这是一个后台提取...
-
我希望一些服务在应用程序运行时在后台运行,甚至处于后台状态。该怎么办。
-
在它运行时很容易做到。只要调用你想要的。在后台有点棘手,您的应用程序只能在后台运行 Apple 预先确定的类型,即 GPS、音频等。或者,在 iOS7 中,您可以使用静默推送通知手动触发 perormFetchWithCompletion。 (developer.apple.com/library/ios/releasenotes/General/…) - 多任务增强。但这再次受到 APNS + iOS 的限制,以避免垃圾邮件。人们不希望应用在不知情的情况下关闭后进行繁重的计算......
标签: ios iphone ios7 cocos2d-iphone