Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support iOS 7 background updates #110

Closed
mikejohnstn opened this issue Aug 8, 2013 · 11 comments
Closed

Support iOS 7 background updates #110

mikejohnstn opened this issue Aug 8, 2013 · 11 comments
Milestone

Comments

@mikejohnstn
Copy link
Contributor

Could be via the new multitasking API, or perhaps push notifications.

@jleandroperez
Copy link
Contributor

Ref: b2ace9b and 5325879

@agiletortoise
Copy link

What is the state of background refresh support and do you have any example code for recommended implementation?

@gazzer82
Copy link

gazzer82 commented Oct 7, 2013

Would also like to know this.

Cheers

Gareth

@jleandroperez
Copy link
Contributor

Ref: 99bf9d3

@jleandroperez
Copy link
Contributor

@agiletortoise @gazzer82 hello there!. Background sync'ing is already implemented. We'll be updating the documentation shortly. In order to wire it, you should do something like this in your App Delegate:

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    self.newDataReceived = NO;
    NSTimeInterval const TimeoutInSeconds = 15;

    [self.simperium forceSyncWithTimeout:TimeoutInSeconds completion:^(BOOL success) {
        UIBackgroundFetchResult result = (self.newDataReceived) ? UIBackgroundFetchResultNewData : UIBackgroundFetchResultNoData;
        completionHandler(result);
    }];
}

In the current implementation, the 'forceSync' callback returns a boolean indicating success. So, you'd need to track yourself if new data was received. (That API might change, so we make it easier than that!).

In order to track 'newDataReceived', you should set all bucket's delegate:

    [simperium setAllBucketDelegates:self];

And do something like:

- (void)bucket:(SPBucket *)bucket didChangeObjectForKey:(NSString *)key forChangeType:(SPBucketChangeType)change memberNames:(NSArray *)memberNames
{
    self.newDataReceived = YES;
}

I'll keep you posted. If you see anything weird, just let me know.

Thanks!

@agiletortoise
Copy link

Thanks, I'll play with this soon.

@mikejohnstn
Copy link
Contributor Author

Been thinking about this...we're not super pleased with how you have to use this, and the approach using timeouts isn't great, so we're going to push this back a bit until we have a chance to rethink some things.

Generally we need to make it easier to track whether (and how many) changes are pending (#136).

@gazzer82
Copy link

gazzer82 commented Mar 6, 2014

Hi @mikejohnstn any update on this implementation, don't want to spend a lot of time implementing it to have to re-write everything . . . .

Thanks

Gareth

@jleandroperez
Copy link
Contributor

@gazzer82 hi there,

Although this issue is still valid, and we be will definitely implement a cleaner API, i'm sorry to say that there hasn't been progress, yet, on this front. The 'forceSyncWithCompletion' approach, described above, is still the only way to go (for now!).

@jleandroperez
Copy link
Contributor

Let's make sure #262 is addressed, before Background Fetch is officially updated + released.

@jleandroperez jleandroperez modified the milestones: v0.7.0, v0.7.1 May 9, 2014
jleandroperez added a commit that referenced this issue May 9, 2014
@jleandroperez
Copy link
Contributor

API has been updated as follows. Official documentation will be refreshed shortly.

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [self.simperium backgroundFetchWithCompletion:^(UIBackgroundFetchResult result) {

        completionHandler(result);
    }];
}

Any comments / feedback will be very welcome. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants