Instagram login in iPhone sdk - iphone

I am implementing instagram in my application.I am following the code from "https://github.com/crino/instagram-ios-sdk"
This code is working fine and instagram call is made in the app delegate.
"self.instagram = [[Instagram alloc] initWithClientId:APP_ID delegate:nil]"
But I want to use this in the view controller not in the app delegate.
When I try to do that it is not calling the "-(void)authorize:(NSArray *)scopes" method and so Instagram is not loading.
Please suggest me some way out for this.

Found the solution. My code:
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView.delegate = self;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:kAuthenticationEndpoint, kClientId, kRedirectUrl]]];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
Where: kAuthenticationEndpoint=#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token%22;

My code:
UIWebView *webViewInstagram = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
webViewInstagram.delegate = self;
[webViewInstagram setDelegate:self];
[self.view addSubview:webViewInstagram];
NSString *urlRedirect = #"REDIRECT_URL";
NSString *clientId = #"CLIENT_ID";
NSString *url = [NSString stringWithFormat:#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token",clientId, urlRedirect];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[webViewInstagram loadRequest:request];

Related

How to Read PDF documents from sever using webview?

I have some PDF books over Server,Here is my code to Read these books from sever.
self.webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.scalesPageToFit = YES;
self.webView.delegate = self;
[self.view addSubview:self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"url.pdf"]]];
Using this code nothing appear in webview,but when i add the same book in my resourse folder then its works.Can any one help me how can i fix it using above url ?thanx
Just change your last line to this :
NSString *urlString = #"url.pdf";
NSString *encodedUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *targetURL = [NSURL URLWithString:encodedUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
self.webView loadRequest:request];
The link of pdf file you provided contains file with thousands of pages,so it might take time to load.

create a UIWebView and load a website programmatically

The following is my code. I simply want to load a website page and put a back button on screen. Don't know why nothing shows on the screen.
in .h
#import <UIKit/UIKit.h>
#interface ThirdViewController : UIViewController
{
UIWebView *myWebView;
}
#property (nonatomic, retain) UIWebView *myWebView;
-(IBAction)goBack:(id)sender;
#end
in .m
#import "ThirdViewController.h"
#implementation ThirdViewController
#synthesize myWebView;
-(IBAction)goBack:(id)sender
{
[myWebView goBack];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
[self.view addSubview:myWebView];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(goBack:)];
}
Initialize your webView.
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame];
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:requestObj];
[tempWebview release];
myWebView.delegate=self;
First Initialize Web view .Write The Below Code In Between [Super
ViewDidLoad]; and Nsstring Inisilization.
myWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
myWebView.delegate=self;
[self.view addSubview:myWebView]
Then Load Request Your Code Will Work.
Add the below code into your viewcontroller.m file viewDidLoad method.
UIWebView *webView = [[UIWebView alloc]init];
NSString *urlString = #"http://www.sourcefreeze.com";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
[self.view addSubview:webView];
for complete uiwebview example please refer the below link.
https://sourcefreeze.com/ios-webview-uiwebview-example/

uiwebview not loading the web page

in my program uiwebview is not loading the url address.when i nslogged the request object is not null.however when i nslog the webview.request it returns null.what may be the reason it is not loading
- (void)viewDidLoad {
[super viewDidLoad];
self.web = [[UIWebView alloc] init];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSLog(#"%#",requestObj);
[self.web loadRequest:requestObj];
[web setFrame:CGRectMake(0, 0, 320, 370)];
NSLog(#"%# %#",self.web,self.web.request);
}
the nslog results are
<NSURLRequest http://www.google.com>
<UIWebView: 0xbb17ff0; frame = (0 0; 320 370); layer = <CALayer: 0xbb12f20>> (null)
as per suggestions from this site i changed it from IB and made it to code .i made the class confirm to uiwebview delegate..both the webviewdidstart and webview did finish are being called these are the nslog outputs from these methods
webviewdidstart
webView-----><NSMutableURLRequest >
webView-----><NSMutableURLRequest http://www.google.com>
webview did finish
webView-finished----><NSMutableURLRequest http://www.google.com>
webView-finished----><NSMutableURLRequest http://www.google.com>
still nothing is being called and i think both these methods are called twice
This is a working code, test this out in your application and let us know the outcome
in .h file, add UIWebViewDelegate
in .m file's viewDidLoad, add this:
UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,460.0)];
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:requestObj];
[self.view addSubview:webview];
Now check in the delegates if your page is loading or not:
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(#"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"finished loading");
}
try like this
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self addSubview:webView];
[webView release];

How to Add a PDF Document to a UIWebView using ASIHTTP

I have the following code in viewDidLoad
NSURL *url = [NSURL URLWithString:URL_TO_DOWNLOAD];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
When this is completed I want to view the URL (PDF) downloaded inside my UIWebView. I create a UIWebView programatically however I can't figure out a way to loadRequest my actual ASIHTTP Request.
you could display a pdf in your device by two way.
first by passing the url to UIWebView directly, in this case you do'nt require to download pdf file
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 420)];
NSURL *targetURL = [NSURL URLWithString:#"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
And the second way , you first need to download (As you are doing) then get the path of pdf file from your application bundle,
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *pdfpath = [[NSBundle mainBundle] pathForResource:#"mypdf" ofType:#"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfpath ];
NSURLRequest *pdfRequest = [NSURLRequest requestWithURL:pdfURL ];
[webView loadRequest:pdfRequest];
[self.view addSubview:webView];
[webView release];

website not upload using webview

ihave write the following code
but it does nothing in consloe it shows Unknown scheme, doing nothing
[webview setDeleagte self];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:sourcelinkStr]]];
NSString *strURL = #"https://facebook.com";
NSURL *url = [NSURL URLWithString:strURL];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:url]];
now ,
we have to define Methods For LoadRequest
thanks..