iOS 后台调度任务 Selene from LinkedIn
- 授权协议: 未知
- 开发语言: Objective-C
- 操作系统: iOS
- 软件首页: https://github.com/linkedin/Selene
软件介绍
Selene 是一个 iOS 库,用于在后台调度任务的执行。
使用:
1) 添加 fetch 后台模式到你 app 的 Info.plist 文件。
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;
}
@end3) 添加任务类调度
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];
}
