Search code examples
iosonedrive

OneDrive SDK - IOS Get Special Folder


I am confused to the correct usage of the OneDriveSDK for IOS on the correct way to create a query in order to get all items in the special folder.

I want to get the music items but once I create the request how should it be executed ?

There is no relevant example I can find anywhere. Other types of requests have implementation methods, but not special folders

The url I want to construct is simple enough

https://api.onedrive.com/v1.0/drive/special/music/children

But I am confused on how to use the SDK to create and execute it

@class ODItemRequest, ODURLSessionDataTask;

The furthest I got was

ODSpecialCollectionRequest *musicCollectionRequest = self.client.drive.special.request; 

What would I do next ?

documentation is at

https://github.com/OneDrive/onedrive-sdk-ios/blob/master/docs/overview.md

and the sdk is at

https://github.com/OneDrive/onedrive-sdk-i

ODSpecialCollectionRequest.h

#import "ODModels.h"
#import "ODCollectionRequest.h"

typedef void (^ODItemCompletionHandler)(ODItem *response, NSError *error);

typedef void (^ODSpecialCompletionHandler)(ODCollection *response, ODSpecialCollectionRequest *nextRequest, NSError *error);

/**
* The header for type ODSpecialCollectionRequestBuilder.
*/



@interface ODSpecialCollectionRequest : ODCollectionRequest
@end

Solution

  • First notice that the request you are generating isn't quite right. You want an ODChildrenCollectionRequest, generated from the "Music" folder. To do this you will need to construct the correct URL using method calls (not properties like you have above). This looks like:

    ODChildrenCollectionRequest *request = [[self.client drive] special:@"Music"] children] request];
    

    You then want to execute a get on the children request. This looks like :

    [request getWithCompletion:^(ODCollection *response, ODChildrenCollectionRequest *nextRequest, NSError *error){
         if(!error){
         // Do Stuff with children
         }
    }];
    

    The completion handler takes three parameters

    1. the ODCollection which contains a NSArray of ODItem called values these are the children of the music folder.
    2. Another ODChildrenCollectionRequest, By default we only return the first 200 items in a collection, this is another request you can issue that will return the next page of items.
    3. An NSError object, this will be nil unless there was an error somewhere along the request.