Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 1, 2012, 03:33 PM   #1
newtoiphonesdk
macrumors 6502a
 
Join Date: Jul 2010
Upload embedded video from app to facebook

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?
newtoiphonesdk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC