Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I am using this tutorial, but having problems. This is going in a viewController that has a webview in it. The viewController is pushed from a Table View that lists all video files in app. When the row of the Table View is selected, it stores the path to a NSString, and then passes that to the viewController and pushes to that view. The video loads fine and plays, but I am trying to get it to where I can upload the video to facebook. I have the facebook app all set up, but am running into problems, or don't understand the tutorial well. Here is my viewController (the one that plays the movie in a webview)'s .h:

Code:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "Facebook.h"
@interface ArchiveMovieViewController : UIViewController <UINavigationControllerDelegate,FBSessionDelegate, FBRequestDelegate>{
    NSString *selectedCountry;
    IBOutlet UIWebView *webview;
    Facebook *facebook;
}
-(IBAction)share;
-(void)facebookbutton;
@property (nonatomic, retain) NSString *selectedCountry;
@property (nonatomic, retain) Facebook *facebook;

@end

Here is the .m
Code:
#import "ArchiveMovieViewController.h"
#import "Facebook.h"

@implementation ArchiveMovieViewController
@synthesize selectedCountry, facebook;


- (void)viewDidLoad
{
    facebook = [[Facebook alloc] initWithAppId:@"358786560836750" andDelegate:self];
}
-(IBAction) share {
    [self facebookbutton];
}
- (void) facebookbutton {
    NSArray* permissions = [[NSArray alloc] initWithObjects:
                            @"publish_stream", nil];
    [facebook authorize:permissions];
    [permissions release];
}
- (void)fbDidLogin {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    
    NSString *proud = [[documentsDirectoryPath stringByAppendingPathComponent:@"archives"] stringByAppendingPathComponent:selectedCountry];
    
    NSString *content = [proud stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSData *videoData = [NSData dataWithContentsOfFile:content];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, selectedCountry,
                                   @"video/quicktime", @"contentType",
                                   @"Video Test Title", @"title",
                                   @"Video Test Description", @"description",
                                   nil];
    [facebook requestWithGraphPath:@"me/videos"
                         andParams:params
                     andHttpMethod:@"POST"
                       andDelegate:self];
}
- (void)viewWillAppear:(BOOL)animated
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    
    NSString *proud = [[documentsDirectoryPath stringByAppendingPathComponent:@"archives"] stringByAppendingPathComponent:selectedCountry];
    
    NSString *content = [proud stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];    
    NSURL *url = [NSURL URLWithString:content];   
    [webview loadRequest:[NSURLRequest requestWithURL:url]];

}
-(void)fbDidNotLogin:(BOOL)cancelled {
	NSLog(@"did not login");
}
- (void)request:(FBRequest *)request didLoad:(id)result {
	if ([result isKindOfClass:[NSArray class]]) {
		result = [result objectAtIndex:0];
	}
	NSLog(@"Result of API call: %@", result);
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"Failed with error: %@", [error localizedDescription]);
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
}

-(void) dealloc {
    [selectedCountry release];
    [facebook release];
    [super dealloc];
}
@end

In my appDelegate.m file, I added:
Code:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[_viewController facebook] handleOpenURL:url];
}
but, it gave me error:
Code:
unknown receiver _viewController, did you mean UIViewController?
When I click the button that I want to upload to Facebook, it goes to the Facebook app, has me login, I click Okay for the permissions, and it goes back to the app, but nothing happens in the app, and nothing gets uploaded. Any thoughts to what is going wrong?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.