-
Notifications
You must be signed in to change notification settings - Fork 78
3. Programmatic API Usage
(Please notice that programmatic API usage is a feature available starting in v5.)
- (void)getMediaListAtPath:(NSString *)path completion:(nullable FPSimpleAPIMediaListCompletionBlock)completion;
Requests a media list at a given path asynchronously.
NOTE: Results are NOT paginated. If you would prefer the results to be paginated, please use -getMediaListAtPath:startPage:success:failure:
instead.
--
- (void)getMediaListAtPath:(NSString *)path startPage:(NSUInteger)startPage completion:(nullable FPSimpleAPIMediaListCompletionBlock)completion;
Requests a media list at a given path asynchronously where the results are paginated.
NOTE: When there's more than one page of results, the success block will include a nextPage
value greater than 0
that can be used as the startPage
value for a subsequent call to this method.
--
- (void)getMediaInfoAtPath:(NSString *)path completion:(nullable FPSimpleAPIMediaCompletionBlock)completion progress:(nullable FPSimpleAPIProgressBlock)progress;
Requests a media at a given path asynchronously.
--
- (void)saveMediaAtLocalURL:(NSURL *)localURL named:(NSString *)name withMimeType:(NSString *)mimetype atPath:(NSString *)path completion:(nullable FPSimpleAPIMediaCompletionBlock)completion progress:(nullable FPSimpleAPIProgressBlock)progress;
Saves some media from a local NSURL
to a given path in the source asynchronously.
--
- (void)saveMediaRepresentedByData:(NSData *)data named:(NSString *)name withMimeType:(NSString *)mimetype atPath:(NSString *)path completion:(nullable FPSimpleAPIMediaCompletionBlock)completion progress:(nullable FPSimpleAPIProgressBlock)progress;
Saves some media represented by NSData
to a given path in the source asynchronously.
--
- (void)saveMediaInfo:(FPMediaInfo *)mediaInfo named:(NSString *)name atPath:(NSString *)path completion:(nullable FPSimpleAPIMediaCompletionBlock)completion progress:(nullable FPSimpleAPIProgressBlock)progress;
Saves some media represented by a FPMediaInfo
to a given path in the source asynchronously.
--
- (void)suspendAllRequests;
Suspends all the requests enqueued for execution.
--
- (void)resumeAllRequests;
Resumes all the requests enqueued for execution.
--
- (void)cancelAllRequests;
Cancels all the requests enqueued for execution and those currently running.
FPSource *source = [FPSource sourceWithIdentifier:FPSourceDropbox];
FPSimpleAPI *api = [FPSimpleAPI simpleAPIWithSource:source];
api.delegate = self;
FPSimpleAPIGetMediaListSuccessBlock successBlock = ^(NSArray *mediaList) {
NSLog(@"Got media list: %@", mediaList);
};
FPSimpleAPIFailureBlock failureBlock = ^(NSError *error) {
NSLog(@"Failed with %@", error);
};
[api getMediaListAtPath:@"/"
success:successBlock
failure:failureBlock];
In iOS:
- (void)simpleAPI:(FPSimpleAPI *)simpleAPI requiresAuthenticationForSource:(FPSource *)source
{
FPAuthController *authController = [[FPAuthController alloc] initWithSource:source];
if (authController)
{
[self.navigationController pushViewController:authController animated:YES];
}
else
{
NSLog(@"FPAuthController could not be instantiated.");
}
}
For a full working example, please check FPPicker iOS API Demo
.
In OS X:
- (void)simpleAPI:(FPSimpleAPI *)simpleAPI requiresAuthenticationForSource:(FPSource *)source
{
self.authController = [[FPAuthController alloc] initWithSource:source];
if (self.authController)
{
[self.authController displayAuthSheetInModalWindow:self.view.window
success: ^{
// NO-OP
}
failure: ^(NSError *__nonnull error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert runModal];
}];
}
else
{
NSLog(@"FPAuthController could not be instantiated.");
}
}
For a full working example, please check FPPicker Mac API Demo
.