Adding facebook comment box plugin for web based phonegap app - facebook

I am trying to add the facebook comment box to my web based app but it does not show up when I install on my phone. Is there some special plugin or methodology for getting the facebook comment plugin to work with phonegap and/or ionic? I currently have this plugin in my config:
<gap:plugin name="com.phonegap.plugins.facebookconnect" version="0.9.0">

I managed to do it with iframe also.
I solved resizing with https://github.com/davidjbradshaw/iframe-resizer
for login i had to change the native code.
iOS: MainViewController.m
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if (![url isFileURL] && (navigationType == UIWebViewNavigationTypeLinkClicked))
{ //this is for loading links in external browser
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
} else if ([[url absoluteString] containsString:#"m.facebook.com"] && [[url absoluteString] containsString:#"login"]) {
NSString *forceInAppBrowserJS = [NSString stringWithFormat:
#"var loginWindow = cordova.InAppBrowser.open('%#', '_blank', 'location=yes');\n\
loginWindow.addEventListener('exit', function(){\n\
window.fbIframe.src = window.fbIframe.src;\n\
});", url]; //reload the iframe after login, you have to assign the iframe in js
[theWebView stringByEvaluatingJavaScriptFromString: forceInAppBrowserJS];
return NO;
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
Android: CordovaWebViewClient.java
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains("file://")) {
if (url.contains("m.facebook.com") && url.contains("login")) {
String forceInAppBrowserJS = String.format("var loginWindow = cordova.InAppBrowser.open('%s', '_blank', 'location=yes,hardwareback=yes'); loginWindow.addEventListener('exit', function(){window.fbIframe.src = window.fbIframe.src;});", url);
view.evaluateJavascript(forceInAppBrowserJS, null);
return true;
}
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(browserIntent); //open link in external browser
return true;
}
return helper.shouldOverrideUrlLoading(view, url);
}

The best solution I have found so far is to call the comments box from inside an iframe. The only problems with this methodology so far is logging in and setting the iframe height. I am still working on a solution

Related

autocomplete search bar using google API?

i am the fresher in ios and i want to make the autocomplete search bar using google API... please tell me how can i make it ... only autocomplete search bar using google API ..
i used this following url ,, but how to complete with search bar ...
- (NSString *)description
{
return [NSString stringWithFormat:#"Query URL: %#", [self googleURLString]];
}
- (NSString *)googleURLString
{
NSMutableString *url = [NSMutableString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&sensor=%#&key=%#",
[self.input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
SPBooleanStringForBool(self.sensor), self.key];
if (self.offset != NSNotFound) {
[url appendFormat:#"&offset=%u", self.offset];
}
if (self.location.latitude != -1) {
[url appendFormat:#"&location=%f,%f", self.location.latitude, self.location.longitude];
NSLog(#"%#",url);
}
if (self.radius != NSNotFound) {
[url appendFormat:#"&radius=%f", self.radius];
}
if (self.language) {
[url appendFormat:#"&language=%#", self.language];
}
return url;
}
Check out https://github.com/spoletto/SPGooglePlacesAutocomplete
It's an objective-c wrapper for the Google Places Autocomplete API.
Good Luck!

how to open the web sent by rich push notification outside the apps

now im doing the push notification on iphone by using xcode. When i sending the message/notification to the user that contain URL for the user to open it, so the user will receive the notification and message that contained URL and open it in the webview in the apps. Is it possible to open that URL outside the apps by chrome or safari?
what are coding need to modified in order to connect that clicked URL to open the browser outside the apps?
this is the coding that make the webview is open when clicked on the link.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:#"ua"]) {
if ((navigationType == UIWebViewNavigationTypeLinkClicked) || (navigationType == UIWebViewNavigationTypeOther)) {
[UAInboxMessage performJSDelegate:wv url:url];
return NO;
}
With the use of this code you can open a link to safari browser just pass your link instead of provided
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.daledietrich.com"]];
you can make static method.
+ (void)openBrowser:(NSString *)url {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
and then call it anywhere
[className openBrowser:#"http://rajneesh071.blogspot.in/2013/03/ios-sdk-open-other-app-from-our-app.html"];
If you have rich text in your url then you can make encoding with it.
NSError *err = nil;
NSString *resultStr=[[NSString alloc] initWithContentsOfFile:url encoding:NSUTF8StringEncoding error:&err];

Redirecting Url to app in iphone for linkedIn

I am trying to authorize LinkedIn with iPhone..
I am using 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 have added URL Scheme as http:// and url identifier as
www.myappname.com
however after authorizing , i don't get back to my application from browser.
Any ideas where i am wrong?
i have used a diff approach now, i have used webView inside app and is using it. Works perfect so far.
- (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;
}
You are going to need to register a custom URL scheme, as iOS and OS X don't have a way to redirect a specific host within a URL scheme.
Generally, you can use something like x-myapp: as the url scheme.
Further, the URL Identifier is not a host, but an identifier that describes the URL scheme, much like a UTI identifier for a file type describes a specific file type. For example, you could use com.myCompany.myApp.url or something similar as the identifier.
You should be fine if you create a scheme of form x-myapp: and then use that as the redirect URL.
An example from a 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>
The CFBundleURLName corresponds in the Xcode GUI to URL Identifier.

Open Apple Maps and Start Route from Current Location to Home Immediately in iOS 6.0

I'm wanting to create a link in my application that essentially will be labelled "Take Me Home". When pressed, I want it to open Apple Maps, route from current location to home, and start turn by turn navigation.
I have found this scheme, but it does not do everything I was hoping for:
http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
Here is a working code for opening Maps with routes (including the option to show Google maps for iOS5)
-(IBAction)showMapApp:(id)sender
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:#selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
if(_mode == 1)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
if(_mode == 2)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
if(_mode == 3)
{
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
} else{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
}
Use this For me its working fine::
NSString* url = [NSString stringWithFormat: #"http://maps.apple.com/maps?saddr=44.521358,11.374080&daddr=44.518640,11.362665"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

Can I format an URL to launch Safari from within my app's UIWebView?

My app has a UIWebView that shows a fair amount of content. For some of that content I would like to exit the app, and launch Safari to handle the web content rather than doing it in my UIWebView. Is there an url format that will explicitly launch Safari rather than loading a page in the UIWebView?
Obviously I can't use http:// since that just opens the url in place. Can I use safari:// or something of the sort?
EDIT: Apologies, I wasn't clear originally. I am looking for a solution that involves changing urls on pages without making modifications to my client. Hoping for a native Safari launching pattern along the lines of tel:// for the phone.
Sure. Then just have the UIWebView delegate do:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString * customScheme = #"safari";
NSURL * loadURL = [request URL]; //this is the url the user tapped
if ([[loadURL scheme] isEqual:customScheme]) {
//if the url starts with "safari://"
NSString * absoluteURL = [loadURL absoluteString];
//replace "safari" with "https"
absoluteURL = [absoluteURL stringByReplacingCharactersInRange:NSMakeRange(0,[customScheme length]) withString:#"https"];
NSURL * openURL = [NSURL URLWithString:absoluteURL];
//open the URL in MobileSafari
[[UIApplication sharedApplication] openURL:openURL];
//tell your UIWebView to ignore this request
return NO;
} else {
//this is not a safari:// url, so handle it normally
return YES;
}
}