Permalink
Browse files

Added basic support for displaying a snippet of the website in the im…

…age view when a url is set
  • Loading branch information...
ayanok committed Sep 14, 2011
1 parent 5936968 commit 044cf34e8cccf32bb7e9e6eece6d85f71c4e2b05
View
@@ -0,0 +1,20 @@
+//
+// FBHiddenWebView.h
+// facebook-ios-sdk
+//
+// Created by Andrew Yanok on 9/14/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface FBHiddenWebView : UIView <UIWebViewDelegate>
+{
+ UIWebView *webView;
+}
+
+@property (copy) void (^FBHiddenWebViewCallback)(UIImage*,NSError*);
+
+- (id)initWithFrame:(CGRect)frame url:(NSURL*) _url;
+
+@end
View
@@ -0,0 +1,66 @@
+//
+// FBHiddenWebView.m
+// facebook-ios-sdk
+//
+// Created by Andrew Yanok on 9/14/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "FBHiddenWebView.h"
+
+@implementation FBHiddenWebView
+@synthesize FBHiddenWebViewCallback = _FBHiddenWebViewCallback;
+
+- (id)initWithFrame:(CGRect)frame url:(NSURL*) _url
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
+ webView.delegate = self;
+ webView.scalesPageToFit = YES;
+ [self addSubview:webView];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:_url];
+ [webView loadRequest:request];
+ }
+ return self;
+}
+
+#pragma mark -
+#pragma mark UIWebViewDelegate
+
+- (void)webViewDidStartLoad:(UIWebView *) _webView {
+
+
+}
+
+- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
+ if (_FBHiddenWebViewCallback != nil) {
+ _FBHiddenWebViewCallback (nil, error);
+ }
+}
+
+- (void)webViewDidFinishLoad:(UIWebView *) _webView {
+
+ UIGraphicsBeginImageContext(_webView.bounds.size);
+ CGContextRef context = UIGraphicsGetCurrentContext();
+
+ //Screenshot
+ [_webView.layer renderInContext:context];
+
+ UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ if (_FBHiddenWebViewCallback != nil) {
+ _FBHiddenWebViewCallback (viewImage, nil);
+ }
+}
+
+- (void) dealloc {
+ [_FBHiddenWebViewCallback release], _FBHiddenWebViewCallback = nil;
+ webView.delegate = nil;
+ [webView release], webView = nil;
+ [super dealloc];
+}
+
+@end
@@ -14,6 +14,7 @@
@class FBShadowView;
@class FBUIImageView;
@class FBBackgroundView;
+@class FBHiddenWebView;
#define kFacebookAccessToken @"FACEBOOK-ACCESS-TOKEN"
@@ -32,6 +33,7 @@
FBBackgroundView *backgroundView;
FBUIImageView *imageView;
FBPostView *postView;
+ FBHiddenWebView *hiddenWebView;
}
@property (nonatomic, retain) NSString *facebookAppId;
View
@@ -12,6 +12,7 @@
#import "FBUIButton.h"
#import "FBUIImageView.h"
#import "FBBackgroundView.h"
+#import "FBHiddenWebView.h"
@interface FBPostViewController (Private)
- (void) handleCompletionWithError:(NSError*) _error;
@@ -113,6 +114,16 @@ - (void) addImage:(UIImage*) _image {
- (void) addURL:(NSURL*) _url {
[post setLink:[_url absoluteString]];
+ if (_url) {
+ hiddenWebView = [[FBHiddenWebView alloc] initWithFrame:CGRectMake(postView.bounds.size.width - 80, 60, 70, 70)
+ url:_url];
+ hiddenWebView.hidden = YES;
+ [hiddenWebView setFBHiddenWebViewCallback:^(UIImage *image, NSError * error) {
+ if (image) {
+ imageView.image = image;
+ }
+ }];
+ }
[self showImageView:YES];
}
@@ -273,6 +284,7 @@ - (void)didReceiveMemoryWarning {
}
- (void) dealloc {
+ [hiddenWebView release], hiddenWebView = nil;
[backgroundView release], backgroundView = nil;
[imageView release], imageView = nil;
[_FBPostViewControllerCompletionCallback release], _FBPostViewControllerCompletionCallback = nil;
@@ -19,6 +19,8 @@
710B0E1C1414FB3F000967BE /* FBUIButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 710B0E1A1414FB3F000967BE /* FBUIButton.m */; };
710B0E23141541C6000967BE /* FBUIImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = 710B0E21141541C6000967BE /* FBUIImageView.h */; };
710B0E24141541C6000967BE /* FBUIImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 710B0E22141541C6000967BE /* FBUIImageView.m */; };
+ 71462EBF1420C17C00E5B746 /* FBHiddenWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 71462EBD1420C17C00E5B746 /* FBHiddenWebView.h */; };
+ 71462EC01420C17C00E5B746 /* FBHiddenWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71462EBE1420C17C00E5B746 /* FBHiddenWebView.m */; };
715429E4141F7AF90036BDDA /* FBBackgroundView.h in Headers */ = {isa = PBXBuildFile; fileRef = 715429E2141F7AF80036BDDA /* FBBackgroundView.h */; };
715429E5141F7AF90036BDDA /* FBBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = 715429E3141F7AF80036BDDA /* FBBackgroundView.m */; };
7168BAA214015EB4008C0D07 /* FBPost.h in Headers */ = {isa = PBXBuildFile; fileRef = 7168BAA014015EB3008C0D07 /* FBPost.h */; };
@@ -70,6 +72,8 @@
710B0E1A1414FB3F000967BE /* FBUIButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBUIButton.m; sourceTree = "<group>"; };
710B0E21141541C6000967BE /* FBUIImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBUIImageView.h; sourceTree = "<group>"; };
710B0E22141541C6000967BE /* FBUIImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBUIImageView.m; sourceTree = "<group>"; };
+ 71462EBD1420C17C00E5B746 /* FBHiddenWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBHiddenWebView.h; sourceTree = "<group>"; };
+ 71462EBE1420C17C00E5B746 /* FBHiddenWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBHiddenWebView.m; sourceTree = "<group>"; };
715429E2141F7AF80036BDDA /* FBBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBBackgroundView.h; sourceTree = "<group>"; };
715429E3141F7AF80036BDDA /* FBBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBBackgroundView.m; sourceTree = "<group>"; };
7168BAA014015EB3008C0D07 /* FBPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBPost.h; sourceTree = "<group>"; };
@@ -199,6 +203,8 @@
710B0E22141541C6000967BE /* FBUIImageView.m */,
715429E2141F7AF80036BDDA /* FBBackgroundView.h */,
715429E3141F7AF80036BDDA /* FBBackgroundView.m */,
+ 71462EBD1420C17C00E5B746 /* FBHiddenWebView.h */,
+ 71462EBE1420C17C00E5B746 /* FBHiddenWebView.m */,
);
name = "UI Controls";
sourceTree = "<group>";
@@ -283,6 +289,7 @@
710B0E23141541C6000967BE /* FBUIImageView.h in Headers */,
71E8F377141BB0DB0008AA16 /* FBVideo.h in Headers */,
715429E4141F7AF90036BDDA /* FBBackgroundView.h in Headers */,
+ 71462EBF1420C17C00E5B746 /* FBHiddenWebView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -355,6 +362,7 @@
710B0E24141541C6000967BE /* FBUIImageView.m in Sources */,
71E8F378141BB0DB0008AA16 /* FBVideo.m in Sources */,
715429E5141F7AF90036BDDA /* FBBackgroundView.m in Sources */,
+ 71462EC01420C17C00E5B746 /* FBHiddenWebView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 044cf34

Please sign in to comment.