Load the SDK Asynchronously without server web - facebook

I need to know if it's possible load the javascript SDK without a server web:
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
ref.parentNode.insertBefore(js, ref);
console.log("1");
}(document));
My problem is that the line js.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; doesn't load correctly because calls the url:
GET file://connect.facebook.net/en_US/all.js
and the response is Not Found.
If anyone know what can i do for load asynchronously the javascript SDK for Facebook without server web i would appreciate it.
Thx!!

Copy/Save the all.js file in your app directory and change the line:
js.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
to
js.src = 'your_app/js/all.js';
but have in mind that this is not a good method for production purposes, because you will not be able to follow any updates made from Facebook.

Related

Facebook sharing not working normally

After facebook sharing I need return to my website. But facebook redirect me to https://www.facebook.com/dialog/return/close#=. Earlier all work good. Can you help me with this problem?
Code:
facebook script:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
share link:
<a href='https://www.facebook.com/sharer/sharer.php?u=http%3A//www.mysite.com/share/somepost/1>Share on Facebook</a>

Adding facebook comment box plugin for web based phonegap app

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

Trying to implement JW Player on iOS

I am a newbi in JW and can't seem to implement to simplest player. Help me, please.
I have created an html and put it in my project. in the same place with the jwplayer.flash.swf, jwplayer.html5.js, jwplayer.js
My html file looks like this (Home.html):
<html>
<head>
<title>Title of the document</title>
<script type="text/javascript" src="jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="myKey"</script>
</head>
<body>
<div id='player_8955'></div>
<script type='text/javascript'>
jwplayer('player_8955').setup({
file: "http://www.youtube.com/watch?v=ac7KhViaVqc",
width: "480",
height: "270",
image: "http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg",
});
</script>
</body>
</html>
in the controller class:
- (void)viewDidLoad
{
[super viewDidLoad];
htmlPlayerWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 51, 674,381)];
[self.view addSubview:htmlPlayerWebView];
}
-(void)loadVideo
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"Home" ofType:#"html"];
NSString *HTMLString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[htmlPlayerWebView loadHTMLString:HTMLString baseURL:[NSURL URLWithString:path]];
}
The functions are called. But nothing happens.
You actually can access local files from within the HTML of a UIWebview. Just change your code as such:
-(void)loadVideo
{
NSString *basePath = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:basePath];
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:#"Home" ofType:#"html"];
NSString *HTMLString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[htmlPlayerWebView loadHTMLString:HTMLString baseURL:baseURL];
}
Any relative paths in your HTML will then be referenced from your project files.
I found the problem:
UIWebView doesn't have access to project files. So the jwplayer.js is not loaded.
So either load the player to some web server, or replace
<script type="text/javascript" src="jwplayer.js"></script>
with
<script type="text/javascript">
Content of the file jwplayer.js (right click on jwplayer.js -> view source -> copy -> paste to here)
</script>
In the years since this question was originally posted, JWPlayer has implemented a mobile SDK for iOS, which was at first freely available, and now is maintained exclusively for Enterprise users. There is also a new "Developer Class" account which gives full access for 6 months, free.
This post, and related issues, are perhaps the main motivator for such a move; exchanging the slippery moving target of web views, with their opaque implementation details, in favor of the controlled native environment available to a framework project was a clear win.

How to open twitter page in twitter app from my iphone app?

The page I want to open using twitter app:
https://twitter.com/#!/PAGE
To open twitter app I use the following code:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter://https://twitter.com/#!/PAGE"]];
[[UIApplication sharedApplication] openURL:urlApp];
But this code doesn't seem to work as expected, I got only twitter app launched without the page which i want to show.
You are looking for the following url:
twitter:///user?screen_name=PAGE
Note that Twitter is not installed on all devices. You should check the result of openURL method. If it fails, open the page in Safari with regular url.
The following code opens twitter page on twitter app if it is already installed, otherwise opens twitter on safari:
NSURL *twitterURL = [NSURL URLWithString:#"twitter://user?screen_name=username"];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];
else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.twitter.com/username"]];
Don't forget to replace 'username' with your name.
I know its quite a late response to this question and I agree that, Murat's answer is absolutely correct.
Simply add a check as follows:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter:///user?screen_name=PAGE]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}
I hope this helps someone. Cheers!! :)
This is the full code required in Swift. I am using Swift 4 but i believe it is the same for Swift 3.
let Username = "YOUR_USERNAME_HERE"
let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")!
let webURL = NSURL(string: "https://twitter.com/\(Username)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
// if Twitter app is not installed, open URL inside Safari
application.open(webURL as URL)
}
Don't forget to add the Info keys needed to use canOpenURL:
#Alexey: If you just want to know how to launch twitter from your application do this:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter://"]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}else{
UIAlertView *appMissingAlertView = [[UIAlertView alloc] initWithTitle:#"Twitter App Not Installed!" message:#"Please install the Twitter App on your iPhone." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"Ok",nil];
[appMissingAlertView show];
[appMissingAlertView release];
}

How to load Google Maps Faster in iPhone

in my iPhone application I'm loading the driving directions to a WebView from a bundled html page (because i can't find a way to load it directly to the MapKit), but it taking too much time to load, is there any better way to do so? Like in the iPhone default map application
code :
NSString *filePathString = [[NSBundle mainBundle] pathForResource:#"drive_index" ofType:#"html"];
NSMutableString *html = [[NSMutableString alloc] initWithContentsOfFile: filePathString];
[html replaceOccurrencesOfString: #"varLocation1" withString:loc1
options: NSLiteralSearch range: NSMakeRange(0, [html length])];
[html replaceOccurrencesOfString: #"varLocation2" withString:loc2
options: NSLiteralSearch range: NSMakeRange(0, [html length])];
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
[webView loadHTMLString:html baseURL:aURL];
and the html page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example: Simple Map</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
type="text/javascript"></script>
<script type="text/javascript">
var directionsPanel;
var directions;
var location1="varLocation1";
var location2="varLocation2";
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(location1), 13);
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
directions.load('from: ' + location1 +' to: '+ location2 );
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width:divice-width ; height:350px ; float:top; border: 1px solid black;"></div>
<div id="route" style="width:divice-width; border; 1px solid black;"></div>
</body>
</html>
Have a look at this answer:
Showing Driving Directions in MapKit
It says a way to use the Map Kit (which doesn't include driving directions) and overlay lines directly on top. Here's the site they reference:
http://spitzkoff.com/craig/?p=65
You should definitely see if you can switch to V3 of the Google Maps API. It was specifically designed to load quickly on mobile browsers. The only problem (and it's a big one) is that it doesn't support directions yet.