Wednesday 20 May 2015

DropBox Integration in IOS

DropBox Integration With Handler




1.Configuring your app

Creating a new app





















Consumer key and secret key






2.Creating a URL scheme



******Authenticating the Url Scheme(appdelegate.m)

a)#import <DropBoxWrapper/DropBoxWrapper.h> 
b)Add the following in the app delegate.m

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

    
    if ([[DropBoxWrapper standardWrapper]authenticatingURLSchemeWithURL:url] == YES) {
        return YES;
    }
    
    return NO;
}

******Providing SecretKey and AppKey(appdelegate.m)
Use this in your controller.
[[DropBoxWrapper standardWrapper]initialisingDropBoxIntegrationWithConsumerKey:@"qsbjmgblgs01oxo" andConsumerSecretKey:@"zx5h24u9mcr9jw4"];

******Logging
Use this in your click action.
[[DropBoxWrapper standardWrapper]loginActionWithRootController:self];      
******Uploading files
1.Add #import "DropBoxWrapper.h" to the controller
2.A)Use the following code to write a .txt & upload the text file.
[[DropBoxWrapper standardWrapper]uploadToDropBoxWithText:@"Hi checking uploaded wrapper" fileName:@"123.txt" andLocalDirectory:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] toDestinationDirectory:@"/FourthFolder"];

  Here uploadToDropBoxWithText: is to define the text which you want to write to the text file.
           fileName:@"123.txt" is to give the .txt name.
            toDestinationDirectory: is to specify the folder to which you wish to upload.

  
                                  OR

 B)Use the following code to upload the any file from NSBundle.
 [[DropBoxWrapper standardWrapper]uploadToDropBoxWithFileName:@"abc.jpg" andDirectory:[[NSBundle mainBundle]pathForResource:@"abc" ofType:@".jpg"] toDestinationDirectory:@"/FouthFolder"]; 
       Here uploadToDropBoxWithFileName: is used to give the file name .


******Downloading Files 
Use the  following code to download file. 
[[DropBoxWrapper standardWrapper]downloadFromDropBoxWithFilePath:@"/FourthFolder/xyz.txt" toDirectory:NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES)[0]];

downloadFromDropBoxWithFilePath: is used to provide the path from where it should be downloaded.

******Listing Folders
[[DropBoxWrapper standardWrapper]listDropBoxFilesWithMetadata:@"/"];

listDropBoxFilesWithMetadata: it specifies the root path  


******Creating Folders      
 [[DropBoxWrapper standardWrapper]createDropBoxFolderWithFolderName:@"/FifthFolder"]; 
******Observing Success or Failure
In case if any of the Dropbox application like (Login, File upload,File download and create folder) fails it can be easily observed by using the following wrapper class delegate:
1.Add DropBoxWrapperDelegate to your view controller

2.Call the delegate using [DropBoxWrapper standardWrapper].customDropBoxDelegate = self;

3.Use the following delegate method in your controller
-(void)loginFailure:(DropBoxError)dropBoxerror withErrorMessage:(NSString *)errorMessage
{
    
    

}
Read More

About Me

Popular Posts

Designed ByBlogger Templates