Foursquare integration in iPhone - iphone

I am trying to do the FourSquare integration in iPhone..i couldn't found any good guidelines through Goggling.... Can any one suggest me the Good guidelines or URLs for FourSquare integration in iPhone..
Thanks

Here is the foursquare api link
Example of Foursquare integration link.
Further code for Foursquare integration
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Foursquare";
//check the authentication
if ([Foursquare2 isNeedToAuthorize]) {
//If needed show the webview
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
NSString *url = [NSString stringWithFormat:#"https://foursquare.com/oauth2/authenticate?display=touch&client_id=%#&response_type=code&redirect_uri=%#",OAUTH_KEY,REDIRECT_URL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[webView loadRequest:request];
[webView setDelegate:self];
[self.view addSubview:webView];
[webView release];
mTableView.hidden = YES;
}else{
//Show your view
mTableView.hidden = NO;
[Foursquare2 searchVenuesNearByLatitude:#"40.763" longitude:#"-73.990" accuracyLL:nil altitude:nil accuracyAlt:nil query:#"" limit:#"15" intent:#"" callback:^(BOOL success, id result){
if (success) {
tableData = [[FoursquareParser parseSearchVenuesResultsDictionary:(NSDictionary*)result] retain];
[mTableView reloadData];
}
}];
}
}

Related

How to show loading image while loading the content of the web view in iPhone application

I have an url which need to access in web view and the url is accessing successfully. but the issue is time is taking more to load the url in webview and hence I need to show a loading image while loading an url. I am trying for that, but not able to get it to show loading bar, loading icon or whatever it may be.
And my code is here goes
NSLog(#"Response ==> %#" ,encodedString);
//'encodedstring' is my url which need to access
// code to show a loading image
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0, 0, 320, 470);
[self.view addSubview:indicator];
[indicator release];
[indicator startAnimating];
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:#"%22" withString:#""];
NSURL *url2;
url2 = [[NSURL alloc] initWithString:urlTwo];
NSLog(#"url2:%#", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[indicator stopAnimating];
[[self view] addSubview:webView];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[indicator startAnimating];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[webView stopLoading];
}
Can anybody is here to solve my issue and make the day happy. Thanks in advance.
-(void)webViewDidFinishLoad:(UIWebView *)aWebView
{
[indicator stopAnimating];
}
-(void)webViewDidStartLoad:(UIWebView *)aWebView
{
[indicator startAnimating];
}
-(void)webView:(UIWebView *)aWebView didFailLoadWithError:(NSError *)error
{
[activityView stopAnimating];
}
have u tried that?

How to Download a video using UIWebView

I want to download a the video using web-view but I am not getting how to download it?
my video link is here
the sample code for playing video which I am using is
-(void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {
   NSString* html = [NSString stringWithFormat:#"%#", url];
   [aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:html]]];
}
- (void)viewDidLoad
{
   [super viewDidLoad];
   
  [self embedYouTubeInWebView:#"http://player.vimeo.com/video/32983838" theWebView:myWebView];
   // Do any additional setup after loading the view, typically from a nib.
}
can anyone please help me to download this video?
To download a file i used the following Code. Hope it will work for you too.
- (IBAction)getFileFromFtpServer:(UIView *)sender
{
NSString *stringURL = #"http://player.vimeo.com/video/32983838";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.mpeg4"];
[urlData writeToFile:filePath atomically:YES];
}
}
Try this here your video is playing..
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
webView.delegate=self;
[webView setOpaque:NO];
webView.backgroundColor=[UIColor clearColor];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
CGFloat height = CGRectGetHeight(screen);
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.frame=CGRectMake((width/2) - 10,(height/2) - 54, 20, 20);
activityIndicator.center=self.view.center;
[activityIndicator hidesWhenStopped];
[self playVideo];
}
-(void) playVideo
{
NSURL *url = [NSURL URLWithString:#"http://player.vimeo.com/video/32983838"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[activityIndicator startAnimating];
[webView addSubview:activityIndicator];
}
/* WebViewDidStartLoad */
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[activityIndicator startAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
/* WebViewDidFinishLoad */
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicator stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
/* WebViewdidFailLoadWithError */
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
If I understand correctly and in response to above, google has shut down several "converter sites" due to copyright infringements: http://www.real.com/resources/youtube-to-mp3-converter There are other sites available to download video content from (again, assuming you're abiding by the copyright guidelines) : This lists five sites where you can find and download online videos free. To make sure a video is legal to download, look for licensing information about the video. Typically, videos with a “Creative Commons” license are legal to download, but may have limitations on how you use the video. http://www.real.com/resources/download-one-video

Issue in UIActivityIndicatorView in iPhone?

Currently i am working in iphone app, Using UIWebView (Webpage shown in presentModelViewController) to show webpage on the screen, then i add UIActivityIndicatorView to show in load url request, but the UIActivityIndicatorView didn't show in the screen, i tried my level best, please help me.
Thanks in Advance
I tried this:
- (void)viewDidLoad
{
[super viewDidLoad];
activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame=CGRectMake(140, 240, 40, 40);
[self.view addSubview:activity];
web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate=self;
web.backgroundColor=[UIColor clearColor];
NSURL *url = [NSURL URLWithString:#"http://wrwr.rww.com/erqrrq"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[web loadRequest:req];
[self.view addSubview:web];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activity stopAnimating];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[activity startAnimating];
}
adding your activitiy indicatore View in to your webView like this:-
- (void)viewDidLoad
{
[super viewDidLoad];
activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame=CGRectMake(140, 240, 40, 40);
web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate=self;
web.backgroundColor=[UIColor clearColor];
NSURL *url = [NSURL URLWithString:#"http://wrwr.rww.com/erqrrq"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[web loadRequest:req];
[web addSubview:activity];
[self.view addSubview:web];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activity stopAnimating];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[activity startAnimating];
}
Try This,
- (void)viewDidLoad
{
[super viewDidLoad];
web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate=self;
web.backgroundColor=[UIColor clearColor];
NSURL *url = [NSURL URLWithString:#"http://wrwr.rww.com/erqrrq"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[web loadRequest:req];
[self.view addSubview:web];
activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame=CGRectMake(140, 240, 40, 40);
[self.view addSubview:activity];
[self.view bringSubviewToFront:activity];
}
Define UIActivityIndicatorView after defining UIWebView.
- (void)viewDidLoad
{
[super viewDidLoad];
web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate=self;
web.backgroundColor=[UIColor clearColor];
NSURL *url = [NSURL URLWithString:#"http://wrwr.rww.com/erqrrq"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[web loadRequest:req];
[self.view addSubview:web];
activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame=CGRectMake(140, 240, 40, 40);
[self.view addSubview:activity];
}
The order you add the sub views to the super view is significant. The UIActivityIndicatorView gets added and then the UIWebView overlays it. If you add the UIWebView first, i.e
[self.view addSubview:web];
[self.view addSubview:activity];
the UIActivityIndicatorView will overlay the UIWebView.

Making a call programmatically from iPhone app and returning back to the app after ending the call

I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.

UIWebView leaking

I have a class that extends UIViewController and implements the UIWebViewDelegate, like this:
#interface TableViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate>{
UIWebView *articleWebView;
NSString *link;
UIActivityIndicatorView *activityIndicator;
NSURL * safariUrl;
}
I'm trying to load a web page into the uiwebview, everything works fine, but i'm getting some leaks (like GeneralBlock-56, GeneralBlock-1024 etc) and i can't find out where they come from.
This is what i am doing:
- (void)viewDidLoad {
[super viewDidLoad];
if (articleWebView){
[articleWebView loadHTMLString: #"" baseURL: nil];
[articleWebView release];
articleWebView = nil;
}
articleWebView = [[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,380)];
if (activityIndicator){
[activityIndicator release];
activityIndicator = nil;
}
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/2-24, self.view.bounds.size.height/3-12, 50, 50)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[self.view addSubview:activityIndicator];
link = [link stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
link = [link stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
link = [(NSString*) CFURLCreateStringByAddingPercentEscapes (NULL, (CFStringRef)link, NULL,
NULL, kCFStringEncodingUTF8) autorelease];
NSURL *url = [NSURL URLWithString:link];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self articleWebView] setDelegate: self];
[articleWebView loadRequest:requestObj];
[link release];
}
//////////////////////////////////////////////
-(void)webViewDidFinishLoad:(UIWebView *)webView{
if (activityIndicator){
[activityIndicator stopAnimating];
[activityIndicator release];
activityIndicator = nil;
self.view = articleWebView;
}
//////////////////////////////////////////////
- (void)viewDidUnload {
[super viewDidUnload];
[articleWebView loadHTMLString: #"" baseURL: nil];
[self.articleWebView release];
self.articleWebView = nil;
}
//////////////////////////////////////////////
- (void)dealloc {
self.articleWebView.delegate=nil;
[super dealloc];
}
What am i doing wrong? Thank you in advance.
Along with setting the webView delegate to nil, you should ask your webView to stop loading. Add the following lines of code and then try:
- (void)dealloc {
self.articleWebView.delegate = nil;
[articleWebView stopLoading];
[articleWebView release];
[super dealloc];
}
If articeWebview is an IBOutlet why is it that you want to allocate it??