SBBActivityManager Class Reference

Inherits from SBBBridgeAPIManager : NSObject
Conforms to SBBActivityManagerProtocol
SBBComponent
Declared in SBBActivityManager.h
SBBActivityManager.m

Overview

This class handles communication with the Bridge Scheduled Activities API.

– getScheduledActivitiesForDaysAhead:withCompletion:

This is a convenience method that assumes the default caching policy, which is SBBCachingPolicyFallBackToCached, if caching is enabled. Also implies a default value of 1 for daysBehind. (Deprecated: For backward compatibility only. Use getScheduledActivitiesFrom:to:withCompletion: instead.)

- (NSURLSessionTask *)getScheduledActivitiesForDaysAhead:(NSInteger)daysAhead withCompletion:(SBBActivityManagerGetCompletionBlock)completion

Declared In

SBBActivityManager.h

– getScheduledActivitiesForDaysAhead:cachingPolicy:withCompletion:

This is a convenience method that assumes a default value of 1 for daysBehind. (Deprecated: For backward compatibility only. Use getScheduledActivitiesFrom:to:cachingPolicy:withCompletion: instead.)

- (NSURLSessionTask *)getScheduledActivitiesForDaysAhead:(NSInteger)daysAhead cachingPolicy:(SBBCachingPolicy)policy withCompletion:(SBBActivityManagerGetCompletionBlock)completion

Declared In

SBBActivityManager.h

– getScheduledActivitiesForDaysAhead:daysBehind:cachingPolicy:withCompletion:

Gets all available, started, or scheduled activities for a user. The “daysAhead” parameter allows you to retrieve activities that are scheduled in the future for the indicated number of days past today (to a maximum of four days, at this time). This allows certain kinds of UIs (e.g. “You have N activities tomorrow” or “You have completed N of X activities today”, even when the activities are not yet to be performed). A “daysBehind” parameter allows you to retain previously-cached activities that have not yet been completed that expired within the indicated number of days in the past. This allows UIs that say, e.g., “You left N activities uncompleted yesterday.” Scheduled activities will be returned in the timezone of the device at the time of the request. Once a task is finished, or expires (the time has passed for it to be started), or becomes invalid due to a schedule change on the server, it will be removed from the list of scheduled activities returned from Bridge, and (except for previously-fetched but unfinished tasks within daysBehind) will also be removed from the list passed to this method’s completion handler. (Deprecated: For backward compatibility only. Use getScheduledActivitiesFrom:to:cachingPolicy:withCompletion: instead.)

- (NSURLSessionTask *)getScheduledActivitiesForDaysAhead:(NSInteger)daysAhead daysBehind:(NSInteger)daysBehind cachingPolicy:(SBBCachingPolicy)policy withCompletion:(SBBActivityManagerGetCompletionBlock)completion

Parameters

daysAhead

A number of days in the future (0-4) for which to retrieve available/started/scheduled activities.

daysBehind

A number of days in the past (no limit) for which to include previously-cached but expired and unfinished activities (ignored if the SDK was initialized with useCache=NO).

policy

Caching policy to use (ignored if the SDK was initialized with useCache=NO).

completion

An SBBActivityManagerGetCompletionBlock to be called upon completion.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Declared In

SBBActivityManager.h

– startScheduledActivity:asOf:withCompletion:

Mark a ScheduledActivity as started, as of the time this method is called.

- (NSURLSessionTask *)startScheduledActivity:(SBBScheduledActivity *)scheduledActivity asOf:(NSDate *)startDate withCompletion:(SBBActivityManagerUpdateCompletionBlock)completion

Parameters

scheduledActivity

The ScheduledActivity to be marked as started.

startDate

The date/time as of which the Task was started.

completion

An SBBActivityManagerUpdateCompletionBlock to be called upon completion. Optional.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Discussion

This method notifies the server API that the activity was started, and calls the completion block upon success (or failure) of that notification.

Declared In

SBBActivityManager.h

– finishScheduledActivity:asOf:withCompletion:

Mark a ScheduledActivity as finished, as of the time this method is called.

- (NSURLSessionTask *)finishScheduledActivity:(SBBScheduledActivity *)scheduledActivity asOf:(NSDate *)finishDate withCompletion:(SBBActivityManagerUpdateCompletionBlock)completion

Parameters

scheduledActivity

The ScheduledActivity to be marked as started.

finishDate

The date/time as of which the Task was finished.

completion

An SBBActivityManagerUpdateCompletionBlock to be called upon completion. Optional.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Discussion

Marking a ScheduledActivity as finished without first marking it as having been started tells the server to just delete the scheduled activity.

This method notifies the server API that the scheduled activity was finished, and calls the completion block upon success (or failure) of that notification.

Declared In

SBBActivityManager.h

– deleteScheduledActivity:withCompletion:

Delete a ScheduledActivity from the list of available/started/scheduled activities.

- (NSURLSessionTask *)deleteScheduledActivity:(SBBScheduledActivity *)scheduledActivity withCompletion:(SBBActivityManagerUpdateCompletionBlock)completion

Parameters

scheduledActivity

The ScheduledActivity to be deleted.

completion

An SBBActivityManagerUpdateCompletionBlock to be called upon completion. Optional.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Discussion

This method is equivalent to marking the scheduled activity as finished as of the time the method is called, which has the effect of removing it from the list of available/started/scheduled activities whether or not it had been previously marked as started, but does not actually delete it from the server if it had previously been marked as started. It is provided as a convenience method.

This method notifies the server API to delete the scheduled activity, and calls the completion block upon success (or failure) of that notification.

Declared In

SBBActivityManager.h

– setClientData:forScheduledActivity:withCompletion:

Add client-specific JSON-serializable data to a ScheduledActivity.

- (NSURLSessionTask *)setClientData:(id<SBBJSONValue>)clientData forScheduledActivity:(SBBScheduledActivity *)scheduledActivity withCompletion:(SBBActivityManagerUpdateCompletionBlock)completion

Parameters

clientData

A (relatively small) JSON-serializable object to store in Bridge with the ScheduledActivity. To set to nil, pass [NSNull null].

scheduledActivity

The ScheduledActivity to which the clientData will be attached.

completion

An SBBActivityManagerGetCompletionBlock to be called upon completion. Optional.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Discussion

This data will be stored on this ScheduledActivity object on the Bridge server, for later retrieval via the getScheduledActivitiesForGuid:scheduledFrom:to:withCompletion: method. This is intended to allow storing small amounts of data summarizing the result of performing the activity, e.g. a single computed “score” or the like, and not the full raw results.

The data can be of any JSON-serializable iOS type: NSString, NSNumber, NSNull, or an NSArray or NSDictionary containing only values of a JSON-serializable iOS type or collection thereof (and the keys of the NSDictionary must be of type NSString).

Declared In

SBBActivityManager.h

– updateScheduledActivities:withCompletion:

Update multiple scheduled activities' statuses with the API at one time.

- (NSURLSessionTask *)updateScheduledActivities:(NSArray *)scheduledActivities withCompletion:(SBBActivityManagerUpdateCompletionBlock)completion

Parameters

scheduledActivities

The list of ScheduledActivity objects whose statuses are to be updated to the API.

completion

An SBBActivityManagerUpdateCompletionBlock to be called upon completion. Optional.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Discussion

Only the startedOn, finishedOn, and clientData fields of ScheduledActivity are user-writable, so only changes to those fields will have any effect on the server state.

Declared In

SBBActivityManager.h

– getScheduledActivitiesFrom:to:cachingPolicy:withCompletion:

Gets all the participant’s scheduled activities in the specified date range, filling in any that the server hadn’t previously scheduled because that part of the date range had never been previously requested.

- (NSURLSessionTask *)getScheduledActivitiesFrom:(NSDate *)scheduledFrom to:(NSDate *)scheduledTo cachingPolicy:(SBBCachingPolicy)policy withCompletion:(SBBActivityManagerGetCompletionBlock)completion

Parameters

scheduledFrom

The earlier end of the desired date range for activities to be retrieved.

scheduledTo

The later end of the desired date range for activities to be retrieved.

policy

Caching policy to use (ignored if the SDK was initialized with useCache=NO).

completion

An SBBActivityManagerGetCompletionBlock to be called upon completion.

Return Value

An NSURLSessionTask object so you can cancel or suspend/resume the request.

Declared In

SBBActivityManager.h

– getScheduledActivitiesFrom:to:withCompletion:

This is a convenience method that assumes the default caching policy, which is SBBCachingPolicyFallBackToCached, if caching is enabled.

- (NSURLSessionTask *)getScheduledActivitiesFrom:(NSDate *)scheduledFrom to:(NSDate *)scheduledTo withCompletion:(SBBActivityManagerGetCompletionBlock)completion

Declared In

SBBActivityManager.h

– getCachedSchedulesUsingPredicate:sortDescriptors:fetchLimit:error:

Fetch the cached schedules using the given predicate, sort descriptors, and fetch limit.

- (NSArray<SBBScheduledActivity*> *)getCachedSchedulesUsingPredicate:(NSPredicate *)predicate sortDescriptors:(nullable NSArray<NSSortDescriptor*> *)sortDescriptors fetchLimit:(NSUInteger)fetchLimit error:(NSError **)error

Parameters

predicate

The predicate to use with the fetch request. This must be a SQL-supported predicate and does not support blocks.

sortDescriptors

The sort descriptors to use in sorting the fetched schedules. Optional.

fetchLimit

The number of results to return. If fetchLimit == 0 then it is ignored.

error

The error returned by the request if it fails.

Return Value

An ordered list of the SBBScheduledActivity objects for this request.

Discussion

Note: This request is performed synchronously and will block the calling thread until completed. Additionally, the results bypass the in-memory caching and are fetched directly from Core Data and converted to new instances of SBBScheduledActivity objects. Therefore, these objects will be equal but not the same instance.

Declared In

SBBActivityManager.h