Any examples/tutorials on using Google GData API - Youtube on iphone? - iphone

I need to list a specific users uploaded videos (YouTube) in a UITableView. I've downloaded the GData source and example projects (not iphone specific) but I can't seem to get it to work. Does anybody know of any good (or any at all ;)) tutorials out there?
Best regards,
Magnus

Assuming you have included the GData client libraries to your project, you need to make a call to fetch the user's uploads, and then display them. Here's the simplest way I can think of:
Create an instance variable in your table view controller class that will hold the feed data returned from the YouTube API.
RootViewController.h
#import "GDataYouTube.h"
#import "GDataServiceGoogleYouTube.h"
#interface RootViewController : UITableViewController {
GDataFeedYouTubeVideo *feed;
}
#property (nonatomic, retain) GDataFeedYouTubeVideo *feed;
Inside the implementation file, make a call to the API to fetch all uploaded videos. Inside the callback selector request:finishedWithFeed:error, store the results in whatever format suits, and reload the table view. In the table views cellForRowAtIndexPath method, format the cell as desired:
RootViewController.m
// get the youtube service
GDataServiceGoogleYouTube *service = [self youTubeService];
// feed id for user uploads
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:#"annoyingorange"
userFeedID:uploadsID];
// make API call
[service fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(request:finishedWithFeed:error:)];
Checkout the full source code for RootViewController.

Related

YouTube In WebVIew - iPhone

This is very strange to me...
I have a simple WebView that loads and interacts with the user exactly like safari mobile (iPhone). Now when you visit m.youtube.com in safari, the url changes when you click on a link to something like this...
http://m.youtube.com/watch?gl=US&hl=en&client=mv-google&v=HX6SyoZ5kw8
The problem with this is I don't think that url is being used in my webview... What do I mean? The following code is used to load a url every time the user try's to click on a link, and it works, but I have a problem with Youtube...
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSLog(#"%#",urlString);
VideoURLTextBox.text = urlString;
return YES;
}
When I first start up the webview it loads m.youtube.com and NSLogs() it into my console, but when I decide to click on a video it fails to NSLog() therefore I don't think a new url is being loaded, but when you load m.youtube.com in safari and click on a video you load a url like above, so why does this not NSLog() in my iPhone application?
What your probably seeing is that the youtube video is running javascript to play the video, you'd have to intercept the javascript callbacks to see that. Here's a link to the youtube video player api, detailing the callbacks, https://developers.google.com/youtube/js_api_reference#SubscribingEvents
If you just want to embed a youtube video in an iOS application then use this.
Using the mobile YouTube site isn't great, I had lots of problems with it in the past and ended up making a UIWebView category. I came across your question and decided to throw it on github :-)
https://github.com/enigmaticflare/UIWebView-YouTube--iOS-Category--ARC-compliant-code
UIWebView+YouTube iOS category to simplify loading youtube videos.
Instructions
1) Add these files to your project
UIWebView+YouTube.h
UIWebView+YouTube.m
2) Initiate UIWebView for example
#property (strong, nonatomic) UIWebView *webView;
#synthesize webView = _webView
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,212,172];
//set the X,Y origin of CGRect to where you want the webView to appear.
_webView.delegate = self;
[_webView loadYouTubeVideoID:#"gR8dO7Cln6M"];
[self.view addSubView:_webView];
Good luck, hope this is what your looking for :)
Adam
m.youtube.com is one giant java web app, delegate methods won't get called, presumably because any loading is written directly to the DOM in the UIWebView. Ran into this problem at work, not sure of the fix but there may be a way to inject the source with a JS click handler.

Facebook iOs sdk iphone : Call from multiple viewcontroller

i followed the official guide from facebook dev doc for implementing SSO from my iphone app,
but all is in the same viewcontroller who hold istance of "Facebook" class.
Now consider i want to login in first viewcontroller of one navigationcontroller and then call graph api from the third viewcontroller of the same navigationcontroller.
I think i can share the variable from one controller to another, but i wish to know if there is some "classic" ways to accomplish this. Indeed what i wish to accomplish in something like:
At the start of app i wish to login and then call graph api (or fql) wherever i need in my app.
Thx
I just did this:
in the YourApp_AppDelegate.h
#import "FBConnect.h"
Facebook *facebook;
#property (nonatomic, retain) Facebook *facebook;
In the YourApp_AppDelegate.m
#synthesize facebook;
Then in your application didFinishLaunchingWithOptions: function:
facebook = [[Facebook alloc] initWithAppId:#"YOUR_FACEBOOK_API"];
From your viewController.h (any of them),
#import "YourApp_AppDelegate.h"
YourApp_AppDelegate *appDelegate;
And then, in your viewController.m viewDidLoad function:
appDelegate = (YourApp_AppDelegate *)[[UIApplication sharedApplication] delegate];
Now, anytime you want to refer to your Facebook singleton, just refer to it like:
[appDelegate.facebook authorize:nil delegate:self];
facebook = [[Facebook alloc] initWithAppId:#"YOUR_FACEBOOK_API" andDelegate:self];
Thats how it looks like on my code :)

Will iPhones webViewDidFinishLoad Detect End of Playback" of Streamed Audio File

I am trying to detect the end of playback of a podcast stream. I am using a loadRequest:[NSURLRequest requestWithURL:location] to load the web page that contains the mp3 file being played back. After looking through the archives of questions, I thought that maybe the implementation of the <UIWebViewDelegate> protocol and specifically the method webViewDidFinishLoad might be the answer. However, after implementing it, I am not seeing this method get called when the audio file finishes. In fact I never see the method get called, leading me to believe I may not have implemented it correctly. Here is what I did:
In the header file I have:
#interface MyWebViewController : UIViewController<UIWebViewDelegate> {
NSURL *location; // holds the web address that will be loaded by this app
IBOutlet UIWebView *theWebView;
}
In the class implementation file I have:
- (void)viewDidLoad {
[super viewDidLoad];
theWebView.delegate = self;
[theWebView loadRequest:[NSURLRequest requestWithURL:location]];
}
- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
NSLog(#"view did finish");
}
Is this proper solution for determining the end of playback of an audio file that is loaded into a web page? If not, what would be a better way to detect the end of playback? If the idea behind this solution is correct, what did I do wrong with this implementation?
I am not sure if this is the problem or not, but you should not shadow your instance variable theWebView within the delegate method. I don't know that changing theWebView to webView is going to solve your problem of the delegate being fired but that is where I would look first.
To answer your original question, this delegate gets called after the Webview response is received not at the end of a streaming connection. I am also looking into a solution for a hook into the completion of a stream.

iPhone - Anyway to get iPhone's Email App Inside Your Own App?

Has anyone every embeded the iPhone's Email program inside your own App?
Let me try and simplify that. Tap Tap Revenge allows you to "Challenge A Friend". When you choose to do so they open the standard iPhone email program (if they mimicked it, it looks damn good), within the application with pre-populated data. All you have to do is select a friend from your contacts and press send. You never leave the Tap Tap Revenge App.
Any ideas how this is done?
You need to include the MessageUI.framework into your project, and inside your header file you need to set the delegate:
#import <MessageUI/MessageUI.h>
#interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
MFMailComposeViewController *email;
}
#property (nonatomic, retain) MFMailComposeViewController *email;
Once you do that, you have a few delegate methods inside your implementation file you need to include (You should check to see the result, but I am trying to keep as little code as needed):
#synthesize email;
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[email dismissModalViewControllerAnimated:YES];
}
Wherever you want to use this, you need to initialize and set it up like this:
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:#"Testing"];
// Optional Attachments
NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:#"albumart.png"]);
[email addAttachmentData:artwork mimeType:#"image/png" fileName:#"albumart.png"];
// Body
[email setMessageBody:#"This is the body"];
// Present it
[self presentModalViewController:email animated:YES];
Further to Garett's great response, should you get the warning:
'MFMailComposeViewController' may not respond to '-setMessageBody:'
add isHTML: so the complete line reads like:
[mail setMessageBody:#"This is the body" isHTML:NO];
There is two answers for that. For applications that should support iPhone OS prior 3.0 the only way to go is to build a custom message composer. Or you may want to have a look at the component built by Joe Hewitt who wrote the Facebook iPhone app.
http://github.com/joehewitt/three20/blob/master/src/Three20/TTMessageController.h
With iPhone SDK 3.0 you are able to use the Mail message composer UI straight out if the box using the MessageUI.framework as explained above.
messagecomposer is the way to go! mails and sms inside the app, run from iOS 3.1. need sdk 4

How to save and view a pdf file through an app on iPhone?

I am trying to save a pdf file in SQLite. I think it will be possible by saving the pdf file as blob. And the problem starts here, how to view that file within the iPhone app now?
I know it can be done using this code:-
#interface PDFViewController : UIViewController {
UIWebView *webView;
NSURL *pdfUrl;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) NSURL *pdfUrl;
#end
#implementation PDFViewController
#synthesize webView, pdfUrl;
- (void)viewDidLoad {
[super viewDidLoad];
// Tells the webView to load pdfUrl
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
But what should be the value of the pdfUrl,I am confused...
And if I retrieve it from the DB it will be in a blob format(methinks) so how to convert it into a NSdata object?
Thank You All.
The problem is that WebView does the URL loading, and it won't understand things like non-http requests; yet your application is trying to serve the data. So basically, you're out of luck, unless you can deserialise the blob out of the sqllite database, write it to a file (in /tmp, say) and then open up a file:/// URL from the NSWebView - but I don't believe that the object will let you do that.
You might be able to invoke the [UIWebView loadData:MIMEType:textEncodingName:baseURL:] method, which will allow you to extract the NSData blob from the sqllite database, supply a mime-type of application/pdf, stick in a dummy text encoding (UTF-8) and base URL, and then it might do what you want. But I'd be tempted to try that at least.
the pdfUrl is the web address of the PDF you are tryign to download from the website. (ie http://website.com/mypdf.pdf)
Read the documentation on NSData, it has a method to allow you to create NSData objects based no what you pull out using sqlite.