Selene 2.0.0

Selene 2.0.0

测试已测试
Lang语言 Obj-CObjective C
许可证 Apache-2.0
发布上次发布2018年9月

Kirollos Risk,《a href="/owners/5007">Jacek Suliga 维护。



Selene 2.0.0

Selene: Background Task Scheduler

Selene 是一个 iOS 库,它可以在 后台获取 上安排任务的执行。

Build Status

(安装指南

(CocoaPods

将以下内容添加到您的 Podfile 中:pod Selene

(子模块

您还可以将此仓库作为子模块添加,并将 Selene 文件夹中的所有内容复制到您的项目中。

(使用

1) 在您应用的 Info.plist 文件中添加 fetch 后台模式。

2) 创建一个任务

任务必须遵循 SLNTaskProtocol。例如

@interface SampleTask: NSObject<SLNTaskProtocol>
@end

@implementation SampleTask

+ (NSString *)identifier {
  return NSStringFromClass(self);
}

+ (NSOperation *)operationWithCompletion:(SLNTaskCompletion_t)completion {
  NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
    // Do some work ....
    completion(UIBackgroundFetchResultNoData);
  }];
  return operation;
}

+ (CGFloat)averageResponseTime {
  return 5.0;
}

+ (SLNTaskPriority)priority {
  return SLNTaskPriorityLow;
}

@end

3) 将任务类添加到调度器

NSArray *tasks = @[[SomeTask class]];
// Run the scheduler every 5 minutes
[SLNScheduler setMinimumBackgroundFetchInterval:60 * 5];
// Add the tasks
[SLNScheduler scheduleTasks:tasks];

在应用代理中

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  [SLNScheduler startWithCompletion:completionHandler];
}

感兴趣?请参阅博文