TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2018 |
Maintained by Michael Curd, Josh Friedman, Adam Sorrin, Ze Qian Zhang.
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:
The recommended way to use the library is through a Cocoapod, available here.
platform :ios, '8.0'
target 'TargetName' do
pod 'AZSClient'
end
The other way to use the library is to build the framework manually:
AZSClient.xcodeproj
in Xcode.AZSClient.framework
file on your Desktop.You can then import the framework file into your application by doing the following:
AZSClient.framework
into your Xcode project navigator.libxml2.2.tbd
and add it to your project.#import <AZSClient/AZSClient.h>
If you are using Swift, you will need to create a bridging header and import <AZSClient/AZSClient.h> there:
Bridging-Header.h
, and add the above import statement.ProjectName/Bridging-Header.h
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.
The following functionality is all coming soon:
If you are having problems with the library, turning on logging may help. Some notes:
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.