EmbedlyWithBlocks 是一个用于 http://embed.ly 的 API 系列的 Objective-C 库(目前支持 Embed 和 Extract API)。Embed.ly有官方的 iOS 库 https://github.com/embedly/embedly-ios,EmbedlyWithBlocks 可以作为替代品使用。
EmbedlyWithBlocks 在以下方面优于官方库:
将 EmbedlyWithBlocks 文件夹拖到您的项目中。在您的 app 委托的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中添加以下代码:[EmbedlyClient sharedClient].APIKey = @"YOURAPIKEY";
在您想要使用该库的文件中,进行 #import "EmbedlyClient.h"。
如果您想传递任何可选的查询参数,请使用在 EmbedlyExtract.h 文件中找到的强类型键创建一个 NSDictionary。例如:
然后,调用 - (void)fetchExtractForURL:(NSString *)requestedURL attributes:(NSDictionary *)attributes completion:(EmbedlyClientFetchExtractCompletionHandler)completion;,传入 Embed.ly 要发送的 URL。
[[EmbedlyClient sharedClient] fetchExtractForURL:@"http://www.vice.com/read/an-afternoon-inside-the-worlds-only-bunny-museum"
attributes:attributes
completion:^(EmbedlyExtract *extract, NSError *error) {
NSLog(@"%@", extract);
}];
查看 EmbedlyExtract.h 和 EmbedlyEmbed.h 文件,了解所有可以返回的属性。
库中返回的所有错误都是从 Embed.ly 的错误代码映射的 http://embed.ly/docs/api/extract/endpoints/1/extract#error-codes
查看示例项目以了解库的简单用法。
如果您有任何问题,请在此处打开一个 Issue,或者在 Twitter @adamontherun 上联系我。