本文介绍了iOS 后台获取和完成块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试定义此方法

- (void)backgroundFetchWithCompletion:(void(^)(UIBackgroundFetchResult))completionHandler;

但是我在 UIBackgroundFetchResult 上收到一个错误,说只允许没有类型的参数列表,我正在关注这个教程和这个 教程,这就是他们定义方法的方式.

However I am getting an error on UIBackgroundFetchResult saying a parameter list without types is only allowed, I was following this tutorial and this tutorial and that is how they define their method.

推荐答案

最后执行某个操作后,必须调用列表中的一个.

After executing some operation at the end you must call one in list.

目标-C

  1. completionHandler(UIBackgroundFetchResultNewData);
  2. completionHandler(UIBackgroundFetchResultFailed);
  3. completionHandler(UIBackgroundFetchResultNoData);

迅捷

  1. completionHandler(.NewData)
  2. completionHandler(.Failed)
  3. completionHandler(.NoData)

完整示例:

目标-C

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  NSLog(@"performFetchWithCompletionHandler");
  //Perform some operation
  completionHandler(UIBackgroundFetchResultNewData);
}

迅捷

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
  println("performFetchWithCompletionHandler")
  //Perform some operation
  completionHandler(.NewData)
}

这篇关于iOS 后台获取和完成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:12