-
Notifications
You must be signed in to change notification settings - Fork 1
/
PinterestViewController.m
104 lines (82 loc) · 3.29 KB
/
PinterestViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// VideoPlayerViewController.m
// Reflection
//
// Created by Suraj Mirajkar on 01/11/12.
//
//
#import "PinterestViewController.h"
@interface PinterestViewController ()
@end
@implementation PinterestViewController
@synthesize webViewPinterest;
@synthesize busyIndicator;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
[webViewPinterest setHidden:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
busyIndicator=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[busyIndicator setFrame:CGRectMake(150, 180, 20, 20)];
[self.view addSubview:busyIndicator];
}
- (IBAction)pinit:(id)sender {
[self postToPinterest];
}
- (IBAction)closeWebVIew:(id)sender {
[webViewPinterest setHidden:YES];
}
- (NSString*) generatePinterestHTML {
NSString *description = @"Post your description here";
NSString *sUrl = [NSString stringWithFormat:@"http://www.alkalima.com/images/08-02/nature.jpg"];
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;
}
- (void) postToPinterest {
NSString *htmlString = [self generatePinterestHTML];
NSLog(@"Generated HTML String:%@", htmlString);
webViewPinterest.backgroundColor = [UIColor clearColor];
webViewPinterest.opaque = NO;
if ([webViewPinterest isHidden]) {
[webViewPinterest setHidden:NO];
}
[webViewPinterest loadHTMLString:htmlString baseURL:nil];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[busyIndicator startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[busyIndicator stopAnimating];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[self setWebViewPinterest:nil];
[super viewDidUnload];
}
@end