iOS背景获取和完成块

我正在试图定义这个方法

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

不过,我得到一个错误UIBackgroundFetchResult说没有types的参数列表只是允许的,我按照本教程和本教程 ,这是他们如何定义他们的方法。

在最后执行一些操作后,您必须在列表中调用一个。

Objective-C的

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

迅速

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

完整的例子:

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) } 

我只是遇到了同样的问题,解决scheme是将其添加到该块定义方法的文件中:

#import "AppDelegate.h"