static NSString* kAppId = @"210849718975311";
In DidLoad :-
permissions = [[NSArray alloc] initWithObjects:@"read_stream", @"publish_stream",@"offline_access", nil];
[permissions retain];
facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
#pragma mark -Login for Facebook
- (void)fbDidLogin
{
[facebook requestWithGraphPath:@"me" andDelegate:self];
// Save authorization information
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
//Remove Old User detail
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"username"];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"password"];
appDelegate.isLogin = YES;
btnLogin.hidden= YES;
btnLogout.hidden = NO;
}
-(void)fbDidNotLogin:(BOOL)cancelled
{
}
- (void)fbDidLogout
{
appDelegate.isLogin = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[facebook invalidateSession];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
// NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in [cookies cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:@"facebook"];
if(domainRange.length > 0)
{
[cookies deleteCookie:cookie];
}
}
btnLogout.hidden = YES;
btnLogin.hidden = NO;
}
#pragma mark - FBRequestDelegate Methods
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
NSLog(@"received response");
}
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
strUser = [appDelegate removeNull:[result objectForKey:@"username"]];
[strUser retain];
strEmail = [appDelegate removeNull:[result objectForKey:@"email"]];
[strEmail retain];
strFname = [appDelegate removeNull:[result objectForKey:@"first_name"]];
[strFname retain];
strLname = [appDelegate removeNull:[result objectForKey:@"last_name"]];
[strLname retain];
UserImage *objUserImg = (UserImage *)[NSEntityDescription
insertNewObjectForEntityForName:@"UserImage"
inManagedObjectContext:appDelegate.managedObjectContext];
if ([strEmail isEqualToString:@""]) {
strEmail = [appDelegate removeNull:[[result objectForKey:@"username"] stringByAppendingString:@"@facebook.com"]];
}
objUserImg.fbUsername = [result objectForKey:@"name"];
objUserImg.fbId = [result objectForKey:@"id"];
strUserImage = [[NSString alloc] initWithFormat:@"https://graph.facebook.com/%@/picture",[result objectForKey:@"id"]];
[strUserImage retain];
strFBId = [result objectForKey:@"id"];
[strFBId retain];
NSString *str = [strFBId stringByAppendingString:@"ThaAfterParty"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:result forKey:@"FBUserDetail"];
[userDefaults synchronize];
}
For Login :-
-(void)onClickLogin
{
[self fbDidLogout];
if (![[self facebook] isSessionValid]) {
[[self facebook] authorize:self.permissions];
}else {
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
}
Cell Details :-
{
static NSString *cellIdentifier = @"CustomCell";
CustomCellAllergy *cell = (CustomCellAllergy *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellAllergy" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCellAllergy *) currentObject;
break;
}
}
}
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
NSDictionary *result = [array objectAtIndex:indexPath.row];
[cell setObjItem:result];
return cell;
}
#pragma mark - Share Methods
-(void)sharetoFB
{
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[objUserImage valueForKey:@"imageurl"]]];
UIImage *img=[UIImage imageWithData:data];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
@"Share on Facebook", @"user_message_prompt",
@" App",@"text",
@" App", @"caption",
img,@"picture",
nil];
[self.facebook requestWithMethodName:@"photos.upload"
andParams:[params mutableCopy]
andHttpMethod:@"POST"
andDelegate:self];
[img release];
}
#pragma mark -
#pragma mark FlickrCellDelegate methods
- (void)loadContentForVisibleCells
{
NSArray *cells = [tblView visibleCells];
[cells retain];
for (int i = 0; i < [cells count]; i++)
{
CommentCell *flickrCell = (CommentCell *)[cells objectAtIndex: i] ;
[flickrCell loadImage];
}
[cells release];
}
- (void)flickrCellAnimationFinished:(CommentCell *)cell {
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
[self loadContentForVisibleCells];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
if (!decelerate)
{
[self loadContentForVisibleCells];
}
}
No comments:
Post a Comment