Home

Awesome

Azure Storage Client Library for iOS (Deprecated)

This project is not being actively maintained. Once a replacement is released, the link will be published here.

Overview

This library is designed to help you build iOS applications that use Microsoft Azure Storage. At the moment, the library is in a preview stage, so thank you for taking a look! It will be some time before the library is stable. In the meantime, we would like to get as much input as possible from the community. Please let us know of any issues you encounter by opening an issue on Github.

The library currently supports almost all blob operations (some exceptions noted below.) Other services (table, queue, file) are forthcoming, depending on demand.

To use this library, you need the following:

How to get started

The recommended way to use the library is through a Cocoapod, available here. Reference documention is available here.

Podfile

platform :ios, '8.0'

target 'TargetName' do
  pod 'AZSClient'
end

Framework

The other way to use the library is to build the framework manually:

  1. First, download or clone the azure-storage-ios repo.
  2. Go into azure-storage-ios -> Lib -> Azure Storage Client Library, and open AZSClient.xcodeproj in Xcode.
  3. At the top-left of Xcode, change the active scheme from "Azure Storage Client Library" to "Framework".
  4. Build the project (⌘+B). This will create an AZSClient.framework file on your Desktop.

You can then import the framework file into your application by doing the following:

  1. Create a new project or open up your existing project in Xcode.
  2. Drag and drop the AZSClient.framework into your Xcode project navigator.
  3. Select Copy items if needed, and click on Finish.
  4. Click on your project in the left-hand navigation and click the General tab at the top of the project editor.
  5. Under the Linked Frameworks and Libraries section, click the Add button (+).
  6. In the list of libraries already provided, search for libxml2.2.tbd and add it to your project.

Import statement

#import <AZSClient/AZSClient.h>

If you are using Swift, you will need to create a bridging header and import <AZSClient/AZSClient.h> there:

  1. Create a header file Bridging-Header.h, and add the above import statement.
  2. Go to the Build Settings tab, and search for Objective-C Bridging Header.
  3. Double-click on the field of Objective-C Bridging Header and add the path to your header file: ProjectName/Bridging-Header.h
  4. Build the project (⌘+B) to verify that the bridging header was picked up by Xcode.
  5. Start using the library directly in any Swift file, there is no need for import statements.

Here is a small code sample that creates and deletes a blob:

-(void)createAndDeleteBlob
{
    // Create a semaphore to prevent the method from exiting before all of the async operations finish.
    // In most real applications, you wouldn't do this, it makes this whole series of operations synchronous.
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    
    // Create a storage account object from a connection string.
    AZSCloudStorageAccount *account = [AZSCloudStorageAccount accountFromConnectionString:@"myConnectionString"];
    
    // Create a blob service client object.
    AZSCloudBlobClient *blobClient = [account getBlobClient];
    
    // Create a local container object with a unique name.
    NSString *containerName = [[NSString stringWithFormat:@"sampleioscontainer%@",[[[NSUUID UUID] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""]] lowercaseString];
    AZSCloudBlobContainer *blobContainer = [blobClient containerReferenceFromName:containerName];
    
    // Create the container on the service and check to see if there was an error.
    [blobContainer createContainerWithCompletionHandler:^(NSError* error){
        if (error != nil){
            NSLog(@"Error in creating container.");
        }
        
        // Create a local blob object
        AZSCloudBlockBlob *blockBlob = [blobContainer blockBlobReferenceFromName:@"blockBlob"];
        
        // Get some sample text for the blob
        NSString *blobText = @"Sample blob text";
        
        // Upload the text to the blob.
        [blockBlob uploadFromText:blobText completionHandler:^(NSError *error) {
            if (error != nil){
                NSLog(@"Error in uploading blob.");
            }
            
            // Download the blob's contents to a new text string.
            [blockBlob downloadToTextWithCompletionHandler:^(NSError *error, NSString *resultText) {
                if (error != nil){
                    NSLog(@"Error in downloading blob.");
                }
                
                // Validate that the uploaded/downloaded string is correct.
                if (![blobText isEqualToString:resultText])
                {
                    NSLog(@"Error - the text in the blob does not match.");
                }
                
                // Delete the container from the service.
                [blobContainer deleteContainerWithCompletionHandler:^(NSError* error){
                    if (error != nil){
                        NSLog(@"Error in deleting container.");
                    }
                    
                    dispatch_semaphore_signal(semaphore);
                }];
            }];
        }];
    }];
    
    // Pause the method until the above operations complete.
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}

In general, all methods in the Storage Client that make service calls are asynchronous, roughly in the style of NSURLSession. When you call methods on the Storage Client that interact with the Storage Service, you need to pass in a completion handler block to handle the results of the operation. Service calls will return before the operation is complete.

More detailed examples can be found in the test code; better samples are coming soon. Also coming soon: API docs, a getting-started guide, and a downloadable framework file. This page will be updated with the relevant links when they're available.

Functionality

Missing functionality

The following functionality is all coming soon:

Specific areas we would like feedback on:

Logging

If you are having problems with the library, turning on logging may help. Some notes:

Internals

If you would like to look at the internals of the library, please do, but be aware that we will be iterating over the next several releases, drastic changes may occur. If you would like to run the tests, you will need to provide your own credentials in the test_configurations.json file. You will also have to change the scheme to actually build and run the tests, and you may need to enable code signing as well.