测试已测试 | ✓ |
Lang语言 | Obj-CObjective C |
许可 | MIT |
发布上次发布 | 2018年3月 |
由Michael Curd、Josh Friedman、Adam Sorrin、Ze Qian Zhang维护。
此库旨在帮助您构建使用Microsoft Azure Storage的iOS应用程序。
目前,该库处于预览阶段,感谢您查看!在本库稳定之前,我们将从社区获得尽可能多的反馈。如有问题,请在GitHub上提交问题。
该库目前支持几乎所有Blob操作(以下有一些例外)。其他服务(表、队列、文件)将根据需求提供。
要使用此库,您需要以下内容:
推荐使用Cocoapod方式使用该库,可在此处找到。
platform :ios, '8.0'
target 'TargetName' do
pod 'AZSClient'
end
另一种使用库的方式是手动构建框架
AZSClient.xcodeproj
。AZSClient.framework
文件。然后,您可以通过以下方式将框架文件导入到应用程序中:
AZSClient.framework
拖放到Xcode项目导航器中。libxml2.2.tbd
并将其添加到项目中。#import <AZSClient/AZSClient.h>
如果您使用Swift,您需要创建一个桥接头并将其添加到
Bridging-Header.h
,并添加上述导入语句。ProjectName/Bridging-Header.h
以下是一个创建和删除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);
}
通常情况下,Storage Client中的所有进行服务调用的方法都是异步的,大致遵循NSURLSession的风格。当您调用与Storage Service交互的Storage Client方法时,您需要传递一个完成处理程序块来处理操作的结果。服务调用将在操作完成之前返回。
更详细的示例可以在测试代码中找到;更好的示例即将到来。
即将推出:API文档、入门指南和可下载的框架文件。当它们可用时,此页面将更新相关链接。
以下功能即将推出
如果您遇到库的问题,启用日志记录可能会有所帮助。以下是一些注意事项:
如果你想查看库的内部架构,请自便,但请注意,我们将在接下来的几个版本中做出迭代,剧变可能会发生。
如果你想运行测试,你需要在test_configurations.json文件中提供自己的凭据。你还需要更改方案以实际构建和运行测试,并且你可能需要启用代码签名。