chings228

Just another WordPress.com site

facebook login for ios part 1 – singleton

for facebook login , you should do 3 things

1. using singleton, why?

singleton allow you to access same variable or method in different page , since you will use facebook class in their view , so start using singleton

2. core part – facebook ios class

3. delegate

facebook use delegate to do callback , as singleton is suggested to use , so we need to set up our own delegate for the views that are using access facebook

;

this part mainly on first part first – use of singleton

following is a typical setup of singleton

singleton.h


#import <;;Foundation/Foundation.h>;;

@interface Singleton : NSObject{

}

+ (id)sharedManager;
@end

singleton.m


#import &amp;quot;Singleton.h&amp;quot;

@implementation Singleton

@synthesize facebook,delegate;

#define kAppId @&amp;quot;119313041424968&amp;quot;

static Singleton *sharedMyManager = nil;

+ (id)sharedManager {
    @synchronized(self) {
        if (sharedMyManager == nil)
            sharedMyManager = [[self alloc] init];
    }
    return sharedMyManager;
}
- (id)init {
    if (self = [super init]) {

        
// init your object,class here , such as array , facebook etc.

    }
    return self;
}

///////////////////////

// method here

////////////////////////
-(void)dealloc
{

    [super dealloc];
    delegate = nil;
}

// Equally, we don't want to generate multiple copies of the singleton.
- (id)copyWithZone:(NSZone *)zone {
    return self;
}

// Once again - do nothing, as we don't have a retain counter for this object.
- (id)retain {
    return self;
}

// Replace the retain counter so we can never release this object.
- (NSUInteger)retainCount {
    return NSUIntegerMax;
}

// This function is empty, as we don't want to let the user release this object.
- (oneway void)release {

}

//Do nothing, other than return the shared instance - as this is expected from autorelease.
- (id)autorelease {
    return self;
}

@end
About these ads

Single Post Navigation

One thought on “facebook login for ios part 1 – singleton

  1. Pingback: facebook ios login - iPhone Dev SDK Forum

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: