Redirect Url to iphone app for relatedIn

I am trying to enable LinkedIn with an iPhone.

I use the following code to redirect url

NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%@&scope=%@&state=%@&redirect_uri=%@" , API_KEY , @"r_fullprofile", @"ASDKASIIWER23432KKQ", @"http://www.myappname.com" ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: authUrl]]; 

In my Url types, I added the URL scheme as http:// and the URL identifier as

  www.myappname.com 

however, after authorization, I will not return to my application from the browser.

Any ideas I'm wrong about?

+1
source share
2 answers

Now I used the diff approach, I used the webView inside the application and use it. While it works fine.

 - (void)viewDidLoad { [super viewDidLoad]; [self.myWebView setDelegate:self]; self.indicator = [[CustomActivityViewer alloc] initWithView:self.view]; NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%@&scope=%@&state=%@&redirect_uri=%@" , API_KEY , @"r_fullprofile rw_nus r_emailaddress r_network w_messages", SCOPE_CODE REDIRECT_URI ]; authUrl = [authUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:authUrl]]]; } -(void)webViewDidStartLoad:(UIWebView *)webView { [self.indicator startAnimating]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { [self.indicator stopAnimating]; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [self.indicator stopAnimating]; } - (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType { NSURL *url = request.URL; NSLog(@"%@", url.absoluteString); if ( [url.host isEqualToString:HOST]) { URLParser *parser = [[URLParser alloc] initWithURLString:url.absoluteString]; NSString *code = [parser valueForVariable:@"code"]; if (code != nil) { NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@", code, REDIRECT_URI_OAUTH, API_KEY, SECRET_KEY]; NSLog(@"%@" , authUrl); authUrl = [authUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [Utilities responseFromURL:[NSURL URLWithString:authUrl] completionBlock:^(NSString *response, NSError *err) { if (err != nil) { [Utilities errorDisplay]; } else { NSDictionary *results = [response JSONValue]; [defaults setObject:[results objectForKey:@"access_token"] forKey:@"access_token"]; } }]; } } return YES; } 
+2
source

You will need to register a custom URL scheme, since iOS and OS X have no way to redirect a specific node in the URL scheme.

Typically, you can use something like x-myapp: as the URL scheme.

In addition, the URL identifier is not a host, but the identifier that describes the URL scheme, like the UTI identifier for a file type, describes a specific file type. For example, you can use com.myCompany.myApp.url or something similar to an identifier.

You should be fine if you create an x-myapp: form layout, and then use it as a redirect URL.

An example of the proposed Info.plist would be:

 <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>com.myCompany.myApp.url</string> <key>CFBundleURLSchemes</key> <array> <string>x-myapp</string> </array> </dict> 

CFBundleURLName in the Xcode GUI matches the URL Identifier .

+2
source

Source: https://habr.com/ru/post/1210074/


All Articles