本文介绍了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.

Objective-C

Objective-C

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

迅速

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

完整示例:

Objective-C

Objective-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