通过电子邮件构建出色的产品!我们省去了同步电子邮件数据与您的应用中的麻烦,这样您可以专注于使您的产品大放异彩。
CIOAPIClient 是一个易于使用的 iOS 和 OS X 库,用于与 Context.IO 2.0 API 通信。它基于 NSURLSession 构建,并提供便于异步基于块的交互方法。
在克隆 git 仓库后,请确保安装示例应用使用的 Cocoapods
cd <repository path>/Example
pod install
打开 "Context.IO iOS Example App.xcworkspace"
要运行示例应用程序,您需要在 CIOAppDelegate.m
中插入您的 Context.IO 消费者密钥和密钥
在 CIOPlayground
目录中有一个预先配置的 Xcode 沙盒(目前针对 Xcode 6.4 + Swift 1.2)。带有库依赖的沙盒在 Xcode 6.4 中有一些小问题,请按照以下步骤使其工作
cd CIOPlayground
pod install
CIOPlayground.xcworkspace
CIOAPIClient
方案(它应该有一个动态框架黄色工具箱图标)CIOPlayground.playground
let s: CIOAPISession = CIOAPISession(consumerKey: "", consumerSecret: "")
authenticator.withAuthentication() { session in
块中使用 CIOAPISession
来构建和执行对 Context.IO API 的签名 NSURLRequests
。
使用您的 API 密钥、消费者密钥和消费者密钥初始化 CIOAPISession
CIOAPISession *session = [[CIOAPISession alloc] initWithConsumerKey:@"your-consumer-key"
consumerSecret:@"your-consumer-secret"];
CIOAPISession
使用 Connect Tokens 来授权个别用户的电子邮件账户。请参阅示例应用程序以了解身份验证过程。您可以在自己的项目中重用或子类化 CIOAuthViewController
,该视图控制器负责身份验证的细节,并且对于大多数目的应该直接可用。
[[session getMessagesWithParams:nil]
executeWithSuccess:^(NSArray *responseArray) {
self.messagesArray = responseArray;
} failure:^(NSError *error) {
NSLog(@"error getting messages: %@", error);
}];
[[session updateFoldersForMessageWithID:message[@"message_id"]
params:@{@"add": @"Test Label"}]
executeWithSuccess:^(NSDictionary *response) {
NSLog(@"Response: %@", response);
} failure:^(NSError *error) {
NSLog(@"error moving message: %@", error);
}];
// 0 is an alias for the first source of an account
[[session getFoldersForSourceWithLabel:@"0" params:nil]
executeWithSuccess:^void(NSArray *folders) {
NSLog(@"Folders: %@", folders);
} failure:^void(NSError *error) {
NSLog(@"Error getting folders: %@", error);
}];
NSDictionary *file = [message[@"files"] firstObject];
CIODownloadRequest *downloadRequest = [session downloadContentsOfFileWithID:file[@"file_id"]];
// Save file with attachment's filename in NSDocumentDirectory
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSURL *fileURL = [documentsURL URLByAppendingPathComponent:file[@"file_name"]];
[session downloadRequest:downloadRequest
toFileURL:fileURL
success:^{
NSLog(@"File downloaded: %@", [fileURL path]);
}
failure:^(NSError *error) {
NSLog(@"Download error: %@", error);
}
progress:^(int64_t bytesRead, int64_t totalBytesRead, int64_t totalBytesExpected){
NSLog(@"Download progress: %0.2f%%",
((double)totalBytesExpected / (double)totalBytesRead) * 100);
}];
CIOAPIClient
需要iOS 7.0或更高版本或Mac OS 10.9或更高版本。
感谢 Kevin Lord 编写了此库的原始版本,Sam Soffes 为 sskeychain 以及 TweetDeck 的 TDOAuth(用于 CIOAPIClient 中的 OAuth 签名生成)做出贡献。
CIOAPIClient
在 MIT 许可协议下发布。有关详细信息,请参阅 LICENSE
文件。