2012-04-15 12 views
0

Ich versuche ein Bild auf Facebook zu posten. Gestern habe ich es bekommen, aber heute habe ich es wieder getestet und es funktioniert nicht: S. Ich kann das Problem nicht finden. Ich habe einige Dinge geändert, aber keine der Methoden, mit denen Facebook interagiert. Ich hoffe, dass mir jemand helfen kann.Veröffentlichen UIImage Facebook Probleme

Ich habe alles in meinem ViewController, weil es nur anmeldet, wenn der Benutzer anfragt.

Ich debuggte es und nur "PublishFacebook" wird aufgerufen, weil ich es nenne. Es geht zu Facebook und fordert die Berechtigungen an und dann kehren Sie zurück und nichts passiert.

Die URL-Schemas sind korrekt.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <dict> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>fb235694579858240</string> 
     </array> 
    </dict> 
</array> 
</plist> 

ViewController.h

import "FBConnect.h"

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate> 

@property (nonatomic, retain) Facebook *facebook; 
-(void)postWall; 

ViewController.m

-(void) publishFacebook:(UIImage *)img { 

    //start the facebook action by clicking any button 
    _publishedImage = img; 
    _facebook = [[Facebook alloc] initWithAppId:@"235694579858240" andDelegate:self]; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { 
     _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
     _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
    } 

    if (![_facebook isSessionValid]) { 
     NSArray *permissions = [[NSArray alloc] initWithObjects: 
           @"user_photos", 
           @"user_likes", 
           @"read_stream", 
           nil]; 
     _facebook.sessionDelegate = self; 
     [_facebook authorize:permissions]; 
    }else{ 
     [self postWall]; 
    } 
} 


    - (void)fbDidLogin { 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
     [defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"]; 
     [defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"]; 
     [defaults synchronize]; 
     [self postWall]; 
    } 

    - (void)postWall{ 

     //NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]; 
     NSData *imageData = UIImagePNGRepresentation(_publishedImage); 
     //[NSData dataWithContentsOfFile:filePath] 
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
             @"Check out my awesome image!. I make it with Trolling for iOS", @"message", imageData, @"source", nil]; 
     [_facebook requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

     NSLog(@"Image posted"); 

     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Image Posted" message:@"Your image was successfully posted of facebook" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
     [alertView show]; 
    } 

    -(void)fbDidNotLogin:(BOOL)cancelled{ 
     if (cancelled) { 
      UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Could not Login" message:@"Facebook Cannot login please try again" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil]; 
      [alertView show]; 
     } 
    } 


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 
    return [_facebook handleOpenURL:url]; 
} 

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
    return [_facebook handleOpenURL:url]; 
} 

Dank

+2

Was ist mit der AppDelegate? Ist es richtig verkabelt, um zu empfangen, was auch immer Facebook zurückbringt, wenn es vom Hintergrund zurückkommt? – Stavash

+0

Nop meine AppDelegate hat nichts, aber warum ich getestet und funktioniert und dann habe ich wieder getestet und hat nicht funktioniert ?. Oder was muss ich auf meine AppDelegate setzen? - (BOOL) Anwendung: (UIApplication *) Anwendung handleOpenURL: (NSURL *) url {? Ich versuche und nichts – Edig

+2

Sie müssen sorgfältig Facebook Tutorial folgen und alles sollte funktionieren: https://developers.facebook.com/docs/mobile/ios/build/ Wenn das nicht hilft bitte posten Sie genau, was nicht funktioniert, so können wir Hilfe. Viel Glück – Stavash

Antwort

1

Sie müssen sorgfältig Facebook Lehrer folgen ial und alles sollte funktionieren: developers.facebook.com/docs/mobile/ios/build

Die einzige Anpassung, die Sie benötigen, ist das Auslösen des Anmeldeprozesses als Ergebnis des UIButton IBAction-Aufrufs. Der Rest ist genau der gleiche Fluss. Dies ist ein ziemlich heikler Prozess und es ist sehr schwer zu debuggen, wenn Sie etwas verpassen.

+0

Danke das implementiere ich dies in meinem Stellvertreter zu posten. [[NSNotificationCenter defaultCenter] addObserver: self-Selektor: @selector (publishFacebook :) Name: @ "facebook" Objekt: nil]; – Edig

Verwandte Themen