Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed the appId .h and added an initialization method. + (Void) ini…

…tWithAppId: (NSString *) appId;
  • Loading branch information...
commit 02076b8c9111ad0b59e72cce78267cf115d1d2d3 1 parent dd97727
@lucascorrea authored
View
2  SCFacebook.xcodeproj/project.pbxproj
@@ -482,6 +482,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SCFacebook/SCFacebook-Prefix.pch";
INFOPLIST_FILE = "SCFacebook/SCFacebook-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -493,6 +494,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SCFacebook/SCFacebook-Prefix.pch";
INFOPLIST_FILE = "SCFacebook/SCFacebook-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
View
7 SCFacebook/AppDelegate.m
@@ -53,14 +53,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[loadingView release];
loadingView.hidden = YES;
+
+ //Your application App ID/API Key Facebook
+ [SCFacebook initWithAppId:@"140422319335414"];
+
return YES;
}
+#pragma mark -
+#pragma mark - SCFacebook Handle
-//SCFacebook Implementation
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
[[NSNotificationCenter defaultCenter] postNotificationName:OPEN_URL object:url];
return YES;
View
4 SCFacebook/Classes/FriendsViewControler.h
@@ -8,9 +8,7 @@
#import <UIKit/UIKit.h>
-@interface FriendsViewControler : UIViewController{
-
-}
+@interface FriendsViewControler : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *friendsArray;
View
8 SCFacebook/Classes/FriendsViewControler.m
@@ -59,7 +59,9 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
+#pragma mark -
#pragma mark - Table view data source
+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0;
@@ -87,9 +89,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.nameLabel.text = [[self.friendsArray objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.photoImageView.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",[[self.friendsArray objectAtIndex:indexPath.row] objectForKey:@"id"]]];
-
+ cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
+}
@end
View
4 SCFacebook/Classes/ViewController.m
@@ -74,7 +74,7 @@ - (void)viewDidDisappear:(BOOL)animated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
- return NO;
+ return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
@@ -105,9 +105,7 @@ - (void)getUserInfo
photoImageView.imageURL = [NSURL URLWithString:[result objectForKey:@"pic"]];
}else{
-
loadingView.hidden = YES;
-
Alert(@"Alert", result);
}
}];
View
7 SCFacebook/SCFacebook/SCFacebook.h
@@ -3,7 +3,7 @@
// SCFacebook
//
// Created by Lucas Correa on 23/11/11.
-// Copyright (c) 2011 Siriuscode Solutions. All rights reserved.
+// Copyright (c) 2012 Siriuscode Solutions. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -26,9 +26,6 @@
#import <Foundation/Foundation.h>
#import "Facebook.h"
-#warning Your application App ID/API Key Facebook
-#define kAppId @"140422319335414"
-
#define OPEN_URL @"OPEN_URL"
#define FQL_USER_STANDARD @"uid, name, email, birthday_date, about_me, pic"
#define PERMISSIONS @"user_about_me",@"user_birthday",@"email", @"user_photos", @"publish_stream"
@@ -54,7 +51,7 @@ typedef enum {
@property (nonatomic, assign) FBPostType postType;
-+ (SCFacebook *)shared;
++ (void)initWithAppId:(NSString *)appId;
+ (BOOL)isSessionValid;
+ (void)loginCallBack:(SCFacebookCallback)callBack;
+ (void)logoutCallBack:(SCFacebookCallback)callBack;
View
128 SCFacebook/SCFacebook/SCFacebook.m
@@ -3,7 +3,7 @@
// SCFacebook
//
// Created by Lucas Correa on 23/11/11.
-// Copyright (c) 2011 Siriuscode Solutions. All rights reserved.
+// Copyright (c) 2012 Siriuscode Solutions. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -27,10 +27,13 @@
#import "SBJSON.h"
-static SCFacebook * _scFacebook = nil;
-
@interface SCFacebook()
-@property (nonatomic, copy) SCFacebookCallback callback;
+
+@property (copy, nonatomic) SCFacebookCallback callback;
+@property (copy, nonatomic) NSString *appId;
+
++ (SCFacebook *)shared;
+
@end
@@ -38,18 +41,20 @@ @interface SCFacebook()
@implementation SCFacebook
@synthesize callback = _callback;
-@synthesize postType;
+@synthesize postType = _postType;
+@synthesize appId = _appId;
#pragma mark -
-#pragma mark Singleton
+#pragma mark - Singleton
+ (SCFacebook *)shared
{
+ static SCFacebook *_scFacebook = nil;
+
@synchronized (self){
static dispatch_once_t pred;
-
dispatch_once(&pred, ^{
_scFacebook = [[SCFacebook alloc] init];
});
@@ -61,7 +66,35 @@ + (SCFacebook *)shared
#pragma mark -
-#pragma mark Private Methods
+#pragma mark - Private Methods
+
+- (void)initWithAppID:(NSString *)appId
+{
+ self.appId = appId;
+ // Initialize Facebook
+ _facebook = [[Facebook alloc] initWithAppId:self.appId andDelegate:self];
+
+ // Initialize user permissions
+ _userPermissions = [[NSMutableDictionary alloc] initWithCapacity:1];
+
+ // Check and retrieve authorization information
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ if ([defaults objectForKey:@"FBAccessTokenKey"]
+ && [defaults objectForKey:@"FBExpirationDateKey"]) {
+ _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
+ _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
+ }
+ if (![_facebook isSessionValid]) {
+ [self loggedOut:NO];
+ }
+
+ //Notification
+ [[NSNotificationCenter defaultCenter] addObserverForName:OPEN_URL object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
+ NSURL *url = (NSURL*)[note object];
+ [self handleOpenURL:url];
+ }];
+}
+
- (BOOL)handleOpenURL:(NSURL *)url
{
@@ -90,47 +123,15 @@ - (void)loggedOut:(BOOL)clearInfo
}
}
-- (SCFacebook *) init
-{
- self = [super init];
- if (self != nil){
-
- // Initialize Facebook
- _facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
-
- // Initialize user permissions
- _userPermissions = [[NSMutableDictionary alloc] initWithCapacity:1];
-
- // Check and retrieve authorization information
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- if ([defaults objectForKey:@"FBAccessTokenKey"]
- && [defaults objectForKey:@"FBExpirationDateKey"]) {
- _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
- _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
- }
- if (![_facebook isSessionValid]) {
- [self loggedOut:NO];
- }
-
- //Notification
- [[NSNotificationCenter defaultCenter] addObserverForName:OPEN_URL object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
- NSURL *url = (NSURL*)[note object];
- [self handleOpenURL:url];
- }];
- }
- return self;
-}
-
- (BOOL)isSessionValid
{
return [_facebook isSessionValid];
}
-- (void)_loginWithAppId:(NSString *)appId callBack:(SCFacebookCallback)callBack
+- (void)_loginCallBack:(SCFacebookCallback)callBack
{
-
- if (!appId || [appId length] == 0) {
- NSString *error = @"Missing app ID. You cannot run the app until you provide this in the code.";
+ if (!self.appId || [self.appId length] == 0) {
+ NSString *error = @"Missing your application App ID/API Key Facebook. You cannot run the app until you provide this in the code.";
Alert(@"ERROR", error)
callBack(NO,error);
@@ -140,7 +141,7 @@ - (void)_loginWithAppId:(NSString *)appId callBack:(SCFacebookCallback)callBack
// Now check that the URL scheme fb[app_id]://authorize is in the .plist and can
// be opened, doing a simple check without local app id factored in here
- NSString *url = [NSString stringWithFormat:@"fb%@://authorize",appId];
+ NSString *url = [NSString stringWithFormat:@"fb%@://authorize",self.appId];
BOOL bSchemeInPlist = NO; // find out if the sceme is in the plist file.
NSArray* aBundleURLTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
if ([aBundleURLTypes isKindOfClass:[NSArray class]] &&
@@ -201,7 +202,7 @@ - (void)_logoutCallBack:(SCFacebookCallback)callBack
}
-- (void)_getUserFQL:(NSString*)fql callBack:(SCFacebookCallback)callBack
+- (void)_getUserFQL:(NSString *)fql callBack:(SCFacebookCallback)callBack
{
if (![_facebook isSessionValid]) {
callBack(NO, @"Not logged in");
@@ -228,7 +229,7 @@ - (void)_getUserFriendsCallBack:(SCFacebookCallback)callBack
-- (void)_feedPostWithLinkPath:(NSString*)_url caption:(NSString*)_caption message:(NSString*)_message photo:(UIImage*)_photo dialog:(BOOL)_dialog callBack:(SCFacebookCallback)callBack
+- (void)_feedPostWithLinkPath:(NSString *)_url caption:(NSString *)_caption message:(NSString *)_message photo:(UIImage *)_photo dialog:(BOOL)_dialog callBack:(SCFacebookCallback)callBack
{
if (![_facebook isSessionValid]) {
callBack(NO, @"Not logged in");
@@ -240,7 +241,7 @@ - (void)_feedPostWithLinkPath:(NSString*)_url caption:(NSString*)_caption messag
//Need to provide POST parameters to the Facebook SDK for the specific post type
NSString *graphPath = @"me/feed";
- switch (postType) {
+ switch (self.postType) {
case FBPostTypeLink:{
[params setObject:@"link" forKey:@"type"];
[params setObject:_url forKey:@"link"];
@@ -304,16 +305,21 @@ - (void)_inviteFriendsWithMessage:(NSString *)_message callBack:(SCFacebookCallb
#pragma mark -
-#pragma mark Public Methods Class
+#pragma mark - Public Methods
+
++ (void)initWithAppId:(NSString *)appId
+{
+ [[SCFacebook shared] initWithAppID:appId];
+}
-+ (BOOL)isSessionValid
++(BOOL)isSessionValid
{
return [[SCFacebook shared] isSessionValid];
}
+ (void)loginCallBack:(SCFacebookCallback)callBack
{
- [[SCFacebook shared] _loginWithAppId:kAppId callBack:callBack];
+ [[SCFacebook shared] _loginCallBack:callBack];
}
+ (void)logoutCallBack:(SCFacebookCallback)callBack
@@ -321,7 +327,7 @@ + (void)logoutCallBack:(SCFacebookCallback)callBack
[[SCFacebook shared] _logoutCallBack:callBack];
}
-+ (void)getUserFQL:(NSString*)fql callBack:(SCFacebookCallback)callBack
++ (void)getUserFQL:(NSString *)fql callBack:(SCFacebookCallback)callBack
{
[[SCFacebook shared] _getUserFQL:fql callBack:callBack];
}
@@ -331,13 +337,13 @@ + (void)getUserFriendsCallBack:(SCFacebookCallback)callBack
[[SCFacebook shared] _getUserFriendsCallBack:callBack];
}
-+ (void)feedPostWithLinkPath:(NSString*)_url caption:(NSString*)_caption callBack:(SCFacebookCallback)callBack
++ (void)feedPostWithLinkPath:(NSString *)_url caption:(NSString *)_caption callBack:(SCFacebookCallback)callBack
{
[SCFacebook shared].postType = FBPostTypeLink;
[[SCFacebook shared] _feedPostWithLinkPath:_url caption:_caption message:nil photo:nil dialog:NO callBack:callBack];
}
-+ (void)feedPostWithMessage:(NSString*)_message callBack:(SCFacebookCallback)callBack
++ (void)feedPostWithMessage:(NSString *)_message callBack:(SCFacebookCallback)callBack
{
[SCFacebook shared].postType = FBPostTypeStatus;
[[SCFacebook shared] _feedPostWithLinkPath:nil caption:nil message:_message photo:nil dialog:NO callBack:callBack];
@@ -349,7 +355,7 @@ + (void)feedPostWithMessageDialogCallBack:(SCFacebookCallback)callBack
[[SCFacebook shared] _feedPostWithLinkPath:nil caption:nil message:@"" photo:nil dialog:YES callBack:callBack];
}
-+ (void)feedPostWithPhoto:(UIImage*)_photo caption:(NSString*)_caption callBack:(SCFacebookCallback)callBack
++ (void)feedPostWithPhoto:(UIImage *)_photo caption:(NSString *)_caption callBack:(SCFacebookCallback)callBack
{
[SCFacebook shared].postType = FBPostTypePhoto;
[[SCFacebook shared] _feedPostWithLinkPath:nil caption:_caption message:nil photo:_photo dialog:NO callBack:callBack];
@@ -369,7 +375,7 @@ + (void)inviteFriendsWithMessage:(NSString *)_message callBack:(SCFacebookCallba
#pragma mark -
-#pragma mark FBSessionDelegate Methods
+#pragma mark - FBSessionDelegate Methods
/**
* Called when the user has logged in successfully.
@@ -403,8 +409,8 @@ - (void)fbDidLogout
self.callback(YES,@"Logout successfully");
}
-- (void)fbDidExtendToken:(NSString*)accessToken
- expiresAt:(NSDate*)expiresAt
+- (void)fbDidExtendToken:(NSString *)accessToken
+ expiresAt:(NSDate *)expiresAt
{
}
@@ -419,7 +425,7 @@ - (void)fbSessionInvalidated
#pragma mark -
-#pragma mark FBRequestDelegate Methods
+#pragma mark - FBRequestDelegate Methods
/**
* Called when the Facebook API request has returned a response. This callback
@@ -487,7 +493,7 @@ - (void)request:(FBRequest *)request didFailWithError:(NSError *)error
#pragma mark -
-#pragma mark FBDialogDelegate Methods
+#pragma mark - FBDialogDelegate Methods
/**
* Called when a UIServer Dialog successfully return. Using this callback
@@ -499,12 +505,12 @@ - (void)dialogDidComplete:(FBDialog *)dialog
self.callback(YES, @"Publish Successfully");
}
-- (void) dialogDidNotComplete:(FBDialog *)dialog
+- (void)dialogDidNotComplete:(FBDialog *)dialog
{
self.callback(NO, @"Dialog dismissed.");
}
-- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
+- (void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error
{
NSLog(@"Error message: %@", [[error userInfo] objectForKey:@"error_msg"]);
self.callback(NO, [[error userInfo] objectForKey:@"error_msg"]);
Please sign in to comment.
Something went wrong with that request. Please try again.