Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LinkedInAttic/Selene
iOS library which schedules the execution of tasks on a background fetch
https://github.com/LinkedInAttic/Selene
Last synced: about 1 month ago
JSON representation
iOS library which schedules the execution of tasks on a background fetch
- Host: GitHub
- URL: https://github.com/LinkedInAttic/Selene
- Owner: LinkedInAttic
- License: apache-2.0
- Created: 2014-08-13T17:44:03.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-13T18:55:35.000Z (about 6 years ago)
- Last Synced: 2024-07-22T19:37:03.779Z (about 2 months ago)
- Language: Objective-C
- Homepage:
- Size: 154 KB
- Stars: 641
- Watchers: 37
- Forks: 37
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Selene: Background Task Scheduler](https://raw.githubusercontent.com/linkedin/Selene/master/selene-banner.png)
Selene is an iOS library which schedules the execution of tasks on a [background fetch](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW56).
[![Build Status](https://travis-ci.org/linkedin/Selene.svg?branch=master)](http://travis-ci.org/linkedin/Selene)
# Installation
## CocoaPods
Add to your Podfile:
`pod Selene`## Submodule
You can also add this repo as a submodule and copy everything in the Selene folder into your project.
# Use
**1) Add the `fetch` background mode in your app’s `Info.plist` file.**
**2) Create a task**
A task must conform to `SLNTaskProtocol`. For example:
```objective-c
@interface SampleTask: NSObject
@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) Add the task class to the scheduler**
```objective-c
NSArray *tasks = @[[SomeTask class]];
// Run the scheduler every 5 minutes
[SLNScheduler setMinimumBackgroundFetchInterval:60 * 5];
// Add the tasks
[SLNScheduler scheduleTasks:tasks];
```In the application delegate:
```objective-c
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[SLNScheduler startWithCompletion:completionHandler];
}
```---
Interested? Here's the [blog post](http://engineering.linkedin.com/ios/introducing-selene-open-source-library-scheduling-tasks-ios)