Posting photos to Facebook fan page with iOS SDK

前端 未结 5 1996
南方客
南方客 2020-12-03 00:11

I\'m trying to upload a photo to a Facebook page I own using the iOS SDK and graph API. I\'ve been able to upload photos to my own wall. I\'ve also been able to post a messa

5条回答
  •  我在风中等你
    2020-12-03 00:35

    I have very similar codes and it works, the only thing that is slightly different is I create the Facebook instance in the AppDelegate ..

    QRSMAppDelegate *delegate = (QRSMAppDelegate *)[[UIApplication sharedApplication] delegate];

    if (![[delegate facebook] isSessionValid]) {
        [[delegate facebook] authorize:permissions];
    

    Like you I initially created the Facebook instance in the view controller and I came out with a lot of weird errors. The issue (I later found out) is ... Facebook responds by passing a URL to the Facebook class instance and from outside the only entry point to your app is the app delegate. (Check the Facebook sdk sample app Hackbook)!

    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

    BOOL ret = [facebook handleOpenURL:url];
    

    .... return(ret); }

    The issue here of course is what if I only use Facebook in a small part of my app and miles away from the app delegate (Facebook instantiation require you to declare the delegate!

    Rather than face equally complex issues in passing the url up, it was actually easier to just alloc init the view controller (Facebook delegate) in the app delegate and pass it up the view hierarchy.

提交回复
热议问题