Skip to content

Commit 451d59a

Browse files
author
Luz Caballero
committed
Removing error code from FBOGSample
1 parent 666f53f commit 451d59a

File tree

12 files changed

+535
-566
lines changed

12 files changed

+535
-566
lines changed

FBGraphAPISample/FBGraphAPISample/GraphAPICallsViewController.m

Lines changed: 43 additions & 384 deletions
Large diffs are not rendered by default.

FBOGSample/FBOGSample/OGShareViewController.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
2323
</view>
2424
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="S0A-lu-mzq">
25-
<rect key="frame" x="70" y="262" width="180" height="44"/>
25+
<rect key="frame" x="20" y="262" width="280" height="44"/>
2626
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2727
<color key="backgroundColor" red="1" green="0.25093179450000003" blue="0.62936305209999999" alpha="1" colorSpace="calibratedRGB"/>
2828
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
29-
<state key="normal" title="share an OG story">
29+
<state key="normal" title="share an OG story - API calls">
3030
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
3131
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
3232
</state>

FBOGSampleSD/FBOGSampleSD.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
EDE8DD251835777F00B46D63 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = EDE8DD231835777F00B46D63 /* InfoPlist.strings */; };
2121
EDE8DD271835777F00B46D63 /* FBOGSampleSDTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EDE8DD261835777F00B46D63 /* FBOGSampleSDTests.m */; };
2222
EDE8DD31183577DA00B46D63 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDE8DD30183577DA00B46D63 /* FacebookSDK.framework */; };
23+
EDE8DD351835783E00B46D63 /* OGShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EDE8DD331835783E00B46D63 /* OGShareViewController.m */; };
24+
EDE8DD361835783E00B46D63 /* OGShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = EDE8DD341835783E00B46D63 /* OGShareViewController.xib */; };
2325
/* End PBXBuildFile section */
2426

2527
/* Begin PBXContainerItemProxy section */
@@ -50,6 +52,9 @@
5052
EDE8DD241835777F00B46D63 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5153
EDE8DD261835777F00B46D63 /* FBOGSampleSDTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBOGSampleSDTests.m; sourceTree = "<group>"; };
5254
EDE8DD30183577DA00B46D63 /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FacebookSDK.framework; path = ../FacebookSDK.framework; sourceTree = "<group>"; };
55+
EDE8DD321835783E00B46D63 /* OGShareViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OGShareViewController.h; sourceTree = "<group>"; };
56+
EDE8DD331835783E00B46D63 /* OGShareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OGShareViewController.m; sourceTree = "<group>"; };
57+
EDE8DD341835783E00B46D63 /* OGShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OGShareViewController.xib; sourceTree = "<group>"; };
5358
/* End PBXFileReference section */
5459

5560
/* Begin PBXFrameworksBuildPhase section */
@@ -113,6 +118,9 @@
113118
children = (
114119
EDE8DD101835777F00B46D63 /* AppDelegate.h */,
115120
EDE8DD111835777F00B46D63 /* AppDelegate.m */,
121+
EDE8DD321835783E00B46D63 /* OGShareViewController.h */,
122+
EDE8DD331835783E00B46D63 /* OGShareViewController.m */,
123+
EDE8DD341835783E00B46D63 /* OGShareViewController.xib */,
116124
EDE8DD131835777F00B46D63 /* Images.xcassets */,
117125
EDE8DD081835777F00B46D63 /* Supporting Files */,
118126
);
@@ -225,6 +233,7 @@
225233
files = (
226234
EDE8DD0C1835777F00B46D63 /* InfoPlist.strings in Resources */,
227235
EDE8DD141835777F00B46D63 /* Images.xcassets in Resources */,
236+
EDE8DD361835783E00B46D63 /* OGShareViewController.xib in Resources */,
228237
);
229238
runOnlyForDeploymentPostprocessing = 0;
230239
};
@@ -243,6 +252,7 @@
243252
isa = PBXSourcesBuildPhase;
244253
buildActionMask = 2147483647;
245254
files = (
255+
EDE8DD351835783E00B46D63 /* OGShareViewController.m in Sources */,
246256
EDE8DD121835777F00B46D63 /* AppDelegate.m in Sources */,
247257
EDE8DD0E1835777F00B46D63 /* main.m in Sources */,
248258
);

FBOGSampleSD/FBOGSampleSD/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1515

1616
@property (strong, nonatomic) UIWindow *window;
17-
@property (strong, nonatomic) ShareViewController *shareViewController;
17+
@property (strong, nonatomic) OGShareViewController *shareViewController;
1818

1919
@end

FBOGSampleSD/FBOGSampleSD/AppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1616
// Override point for customization after application launch.
1717

1818
// Create a LoginUIViewController instance where we will put the login button
19-
ShareViewController *shareViewController = [[ShareViewController alloc] init];
20-
self.shareViewController = shareViewController;
19+
OGShareViewController *ogShareViewController = [[OGShareViewController alloc] init];
20+
self.shareViewController = ogShareViewController;
2121

2222
// Set loginUIViewController as root view controller
23-
[[self window] setRootViewController:shareViewController];
23+
[[self window] setRootViewController:ogShareViewController];
2424

2525
self.window.backgroundColor = [UIColor whiteColor];
2626
[self.window makeKeyAndVisible];

FBOGSampleSD/FBOGSampleSD/OGShareViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
@interface OGShareViewController : UIViewController
11+
@interface OGShareViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
1212

1313
@end

FBOGSampleSD/FBOGSampleSD/OGShareViewController.m

Lines changed: 127 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright (c) 2013 Facebook Inc. All rights reserved.
77
//
88

9+
#import <FacebookSDK/FacebookSDK.h>
910
#import "OGShareViewController.h"
1011

1112
@interface OGShareViewController ()
@@ -14,25 +15,138 @@ @interface OGShareViewController ()
1415

1516
@implementation OGShareViewController
1617

17-
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
18+
- (IBAction)publishOGStoryWithImage:(id)sender
1819
{
19-
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
20-
if (self) {
21-
// Custom initialization
22-
}
23-
return self;
20+
// Retrieve a picture from the device's photo library
21+
/*
22+
NOTE: SDK Image size limits are 480x480px minimum resolution to 12MB maximum file size.
23+
In this app we're not making sure that our image is within those limits but you should.
24+
Error code for images that go below or above the size limits is 102.
25+
*/
26+
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
27+
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
28+
[imagePicker setDelegate:self];
29+
[self presentViewController:imagePicker animated:YES completion:nil];
30+
2431
}
2532

26-
- (void)viewDidLoad
33+
// When the user is done picking the image
34+
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
2735
{
28-
[super viewDidLoad];
29-
// Do any additional setup after loading the view from its nib.
36+
37+
/// Package the image inside a dictionary
38+
NSArray* image = @[@{@"url": [info objectForKey:UIImagePickerControllerOriginalImage], @"user_generated": @"true"}];
39+
40+
// Create an object
41+
id<FBGraphObject> object =
42+
[FBGraphObject openGraphObjectForPostWithType:@"share-sample:tutorial"
43+
title:@"Sharing Tutorial"
44+
image:@"http://i.imgur.com/g3Qc1HN.png"
45+
url:@"https://developers.facebook.com/docs/ios/share/"
46+
description:@"Allow your users to share stories on Facebook from your app using the iOS SDK."];
47+
48+
// Create an action
49+
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
50+
51+
// Set image on the action
52+
//[action setObject:image forKey:@"image"];
53+
54+
// Link the object to the action
55+
[action setObject:object forKey:@"tutorial"];
56+
57+
// Tag one or multiple users using the users' ids
58+
//[action setTags:@[<user-ids>]];
59+
60+
// Tag a place using the place's id
61+
id<FBGraphPlace> place = (id<FBGraphPlace>)[FBGraphObject graphObject];
62+
[place setId:@"141887372509674"]; // Facebook Seattle
63+
[action setPlace:place];
64+
65+
// Dismiss the image picker off the screen
66+
[self dismissViewControllerAnimated:YES completion:nil];
67+
68+
// Check if the Facebook app is installed and we can present the share dialog
69+
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
70+
params.action = action;
71+
params.actionType = @"share-sample:complete";
72+
73+
// If the Facebook app is installed and we can present the share dialog
74+
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
75+
// Show the share dialog
76+
[FBDialogs presentShareDialogWithOpenGraphAction:action
77+
actionType:@"share-sample:complete"
78+
previewPropertyName:@"tutorial"
79+
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
80+
if(error) {
81+
// There was an error
82+
NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
83+
[[[UIAlertView alloc] initWithTitle:@"Error posting to Facebook"
84+
message:@"Please try again later"
85+
delegate:self
86+
cancelButtonTitle:@"OK"
87+
otherButtonTitles:nil] show];
88+
} else {
89+
// Success
90+
NSLog(@"result %@", results);
91+
}
92+
}];
93+
94+
// If the Facebook app is NOT installed and we can't present the share dialog
95+
} else {
96+
// FALLBACK: publish just a link using the Feed dialog
97+
98+
// Put together the dialog parameters
99+
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
100+
@"Sharing Tutorial", @"name",
101+
@"Build great social apps and get more installs.", @"caption",
102+
@"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description",
103+
@"https://developers.facebook.com/docs/ios/share/", @"link",
104+
@"http://i.imgur.com/g3Qc1HN.png", @"picture",
105+
nil];
106+
107+
// Show the feed dialog
108+
[FBWebDialogs presentFeedDialogModallyWithSession:nil
109+
parameters:params
110+
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
111+
if (error) {
112+
// Error launching the dialog or publishing a story.
113+
NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
114+
} else {
115+
if (result == FBWebDialogResultDialogNotCompleted) {
116+
// User canceled.
117+
NSLog(@"User cancelled.");
118+
} else {
119+
// Handle the publish feed callback
120+
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
121+
122+
if (![urlParams valueForKey:@"post_id"]) {
123+
// User canceled.
124+
NSLog(@"User cancelled.");
125+
126+
} else {
127+
// User clicked the Share button
128+
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
129+
NSLog(@"result %@", result);
130+
}
131+
}
132+
}
133+
}];
134+
135+
}
136+
30137
}
31138

32-
- (void)didReceiveMemoryWarning
33-
{
34-
[super didReceiveMemoryWarning];
35-
// Dispose of any resources that can be recreated.
139+
// A function for parsing URL parameters.
140+
- (NSDictionary*)parseURLParams:(NSString *)query {
141+
NSArray *pairs = [query componentsSeparatedByString:@"&"];
142+
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
143+
for (NSString *pair in pairs) {
144+
NSArray *kv = [pair componentsSeparatedByString:@"="];
145+
NSString *val =
146+
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
147+
params[kv[0]] = val;
148+
}
149+
return params;
36150
}
37151

38152
@end

FBOGSampleSD/FBOGSampleSD/OGShareViewController.xib

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4469" systemVersion="13A476u" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4471.1" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3694"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3697.3"/>
55
</dependencies>
66
<objects>
77
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="OGShareViewController">
@@ -13,6 +13,21 @@
1313
<view contentMode="scaleToFill" id="1">
1414
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
1515
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<subviews>
17+
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8dB-0l-tql">
18+
<rect key="frame" x="31" y="253" width="258" height="44"/>
19+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
20+
<color key="backgroundColor" red="0.0" green="0.0" blue="1" alpha="1" colorSpace="calibratedRGB"/>
21+
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
22+
<state key="normal" title="Share OG Story - Share Dialog">
23+
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
24+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
25+
</state>
26+
<state key="highlighted">
27+
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
28+
</state>
29+
</button>
30+
</subviews>
1631
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
1732
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
1833
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>

FBShareSample/FBShareSample/AppDelegate.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1515
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
1616
// Override point for customization after application launch.
1717

18+
// Load the FBLoginView class (needed for login)
19+
[FBLoginView class];
20+
1821
// Create a LoginUIViewController instance where we will put the login button
1922
ShareViewController *shareViewController = [[ShareViewController alloc] init];
2023
self.shareViewController = shareViewController;

FBShareSample/FBShareSample/ShareViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
@interface ShareViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
11+
@interface ShareViewController : UIViewController
1212

1313
@end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy