【发布时间】:2012-03-28 14:22:05
【问题描述】:
目前允许从 iOS 应用分享 pinterest 的最可靠方式是什么?
Pinterest API 尚未公开,唯一建议的分享方式是他们的网络按钮。
【问题讨论】:
-
@mydogisbox 网页按钮对用户来说很不方便,因为您必须显示额外的网页视图并在您的网站上呈现某种针对移动设备优化的页面
标签: iphone objective-c ios pinterest
目前允许从 iOS 应用分享 pinterest 的最可靠方式是什么?
Pinterest API 尚未公开,唯一建议的分享方式是他们的网络按钮。
【问题讨论】:
标签: iphone objective-c ios pinterest
我在我的 iPad 应用中进行了 pinterest 集成。但是,因为 Pinterest 还没有用于发布的 API,所以我使用了以下方法。我只是以编程方式创建一个 HTML 网页,并以编程方式向该页面添加一个 Pin it 按钮。然后我显示一个 Web 视图并允许用户再次单击固定它。这些是更多解释的步骤。
1) 创建一个具有 UIWebView 的 WebViewController。添加关闭按钮,添加 UIWebViewDelegateProtocol、spinner、htmlString 属性。
2) 当用户在您的应用中单击“固定”按钮时,以编程方式生成 HTML 以放入该 UIWebView。在这种情况下,我将不同产品的不同图像放入 HTML 页面。
- (NSString*) generatePinterestHTMLForSKU:(NSString*)sku {
NSString *description = @"Post your description here";
// Generate urls for button and image
NSString *sUrl = [NSString stringWithFormat:@"http://d30t6wl9ttrlhf.cloudfront.net/media/catalog/product/Heros/%@-1.jpg", sku];
NSLog(@"URL:%@", sUrl);
NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(@"Protected URL:%@", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
NSString *buttonUrl = [NSString stringWithFormat:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%@&description=%@\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:@"<html> <body>"];
[htmlString appendFormat:@"<p align=\"center\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></p>", buttonUrl];
[htmlString appendFormat:@"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%@></img></p>", imageUrl];
[htmlString appendFormat:@"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:@"</body> </html>"];
return htmlString;
}
这是我的 HTML 页面生成方法的示例。
3) 创建一个在用户点击您的“固定”按钮时调用的方法,该按钮显示带有图像的 webView,您将发布该图像以及 UIWebView 上的“固定”按钮。这是我的例子:
- (void) postToPinterest {
NSString *htmlString = [self generatePinterestHTMLForSKU:self.flProduct.sku];
NSLog(@"Generated HTML String:%@", htmlString);
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
webViewController.htmlString = htmlString;
webViewController.showSpinner = YES;
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:webViewController animated:YES];
}
4) 在您的 WebViewController 上放置一个“关闭”按钮以关闭它。您还可以添加微调器来跟踪 UIWebView 的加载。
- (IBAction)closeClicked:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
if (showSpinner) {
// If we want to show Spinner, we show it everyTime
[UIHelper startShowingSpinner:self.webView];
}
else {
// If we don't -> we show it only once (some sites annoy with it)
if (!spinnerWasShown) {
[UIHelper startShowingSpinner:self.webView];
spinnerWasShown = YES;
}
}
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[UIHelper stopShowingSpinner];
}
附:我使用相同的方法将 Google Plus 的 +1 按钮添加到 iPad 应用程序。 (它也没有发布API,目前只有只读API)
【讨论】:
如果您只想分享(即在用户板上钉住),那么您可以使用 iphone-URL-Scheme 并调用 Pinterest 应用程序以及参数 url(页面的 URL 到pin)、媒体(要固定的图像的 URL)和 说明(要固定的页面的说明)。如果用户尚未安装,请出示 UIAlertView 并将其转发到 appstore 以下载官方 Pinterest 应用程序。
参考: http://wiki.akosma.com/IPhone_URL_Schemes#Pinterest
打开 Pinterest 应用程序的代码:
NSURL *url = [NSURL URLWithString:@"pinit12://pinterest.com/pin/create/bookmarklet/?url=URL-OF-THE-PAGE-TO-PIN&media=URL-OF-THE-IMAGE-TO-PIN&description=ENTER-YOUR-DESCRIPTION-FOR-THE-PIN"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Pinterest" message:@"Would you like to download Pinterest Application to share?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alert show];
}
UIAlertViewDelegate 方法
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1){
NSString *stringURL = @"http://itunes.apple.com/us/app/pinterest/id429047995?mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
}
【讨论】:
截至 2013 年 5 月 20 日,Pinterest 已发布用于固定内容的 iOS SDK。
查看their Developers site了解更多信息。
【讨论】:
我也高高在上。我什至就 SDK 联系了 Pinterest 团队。我发现的最接近的东西是 github https://github.com/kellan/pinterest.api.php 上的 PHP 包装器。
虽然它不是最好的解决方案,因为它是非官方的 api,很可能会崩溃。
【讨论】:
我尝试将 Pinterest 与自定义 URL 方案集成,也将 Pinterest 应用程序下载到我的设备上,但无法与之集成。
问题是我不想使用 webView 进行集成,所以可以这样做吗,我没有在应用商店中找到任何具有 pinterest 集成的应用程序。
我也用谷歌搜索过,但更糟糕的是,Snapguide 还从他们的应用程序中删除了 pinterest 集成。
我使用 webView 代码固定图像,无需打开完整的 Pinterest 网站,
NSString *urlStr =[NSString stringWithFormat:@"http://pinterest.com/pin/create/bookmarklet/?url=www.<domainname>.com&media=http://<domainname>.files.com/hello.jpg?w=495&description=hello"];
这很容易,但使用 webView 并且我不想要。
【讨论】: