Uploading files with PhoneGap + iPhone - iphone

I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn't provide controls to upload files.
Does PhoneGap provide any mechanisms that allow users to upload files? (images / video, in the case of the iPhone)
I know Titanium allows users to do this, but it's a different animal with its compiled Javascript and proprietary APIs. Thanks for your advice/input.

I believe you might be able to read the files using the PhoneGap API and the upload them using and AJAX post if the server application supported it.
The other option is to write a custom module/Plugin in PhoneGap that could specific to your needs.
Here are some Example Plugins

You can do an xmlhttprequest to the file on a local drive.
I'm not 100% sure if it will work on the iPhone, but webkit should support it.
function getImageBinaries(url) { //synchronous binary downloader for firefox2
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send("");
if (req.status != 200) {
return "";
}
var t = req.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
ff[z] = scc(t.charCodeAt(z) & 255);
}
var b = ff.join("");
return b;
}
Succes,
Erik

Related

Post two images on Facebook with UWP Community Toolkit

Is there a way to post two images in a single post with UWP Community Toolkit?.
I think it is possible, you can check the official sample app of UWP Community Toolkit.
It has encapsulated the twitter apis in its service. And according to the Twitter developer documentation: Uploading Media, it is supported to upload maximum 4 photos in a tweet.
In a word, you can open the project of this sample app, and find SamplePages -> Twitter Service -> TwitterPage.xaml.cs, finally find the SharePictureButton_OnClick event and override the original code:
StorageFile picture = await openPicker.PickSingleFileAsync();
if (picture != null)
{
using (var stream = await picture.OpenReadAsync())
{
await TwitterService.Instance.TweetStatusAsync(TweetText.Text, stream);
}
}
to:
var pictures = await openPicker.PickMultipleFilesAsync();
int num = pictures.Count;
List<IRandomAccessStream> streams = new List<IRandomAccessStream>();
foreach (var picture in pictures)
{
var stream = await picture.OpenReadAsync();
streams.Add(stream);
}
await TwitterService.Instance.TweetStatusAsync(TweetText.Text, streams.ToArray());

detecting if the current code is running as an app or as web page

I'm developing an hybrid application using ionic.
Most of the features would work on mobile web browser. So the final product can be used from an http address as well. But there are certain code segments/features ( such as vibration, background alerts ) which will obviously be for the app version. And those features will only be available on the app version.
What's a good/recommended way to detect the current situation in the code base so that I can do logic such as if (isRunningAsApp) {do this} else {do that}*?
would it be just checking window.location.href and if you get something that starts wiih http:, then it is a mobile app, otherwise it is an app?
This is from Ionic's documentation
angular.module('PlatformApp', ['ionic']).controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});

How to detect if WebGL is on Facebook Canvas

Im currently facing an issue where I am using the Facebook plugin v.7.1.0 for Unity. Im distributing through WebGL, but my app needs to be running both on Facebook, but also outside Facebook. When using FB.Init I get a successful callback, which is what I used to use for testing whether on Facebook canvas or not when deploying for WebPlayer.
So my question is, how do I detect whether the WebGL player is on the facebook canvas or not?
This solution is just posted for anyone who would like the same solution as I used.
The solution was to use a jslib plugin as described here http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
var FacebookCanvasChecker = {
GetSite: function()
{
var url = document.URL;
var returnStr = "";
if (url.indexOf("apps.facebook.com") > -1)
returnStr = "facebook";
else
{
// try with referer
if(document.referrer)
{
url = document.referrer;
if (url.indexOf("apps.facebook.com") > -1)
returnStr = "facebook";
else
returnStr = url;
}
else
returnStr = url;
}
var buffer = _malloc(returnStr.length + 1);
writeStringToMemory(returnStr, buffer);
return buffer;
}
};
mergeInto(LibraryManager.library, FacebookCanvasChecker);
In Unity's WebGL, you can communicate with javascript. link
So, I call a javascript function to check current url by
C#
Application.ExternalCall("GetCurrentUrlType");
JS
function GetCurrentUrlType(){
var url = document.URL;
if (url.indexOf("apps.facebook.com") > -1)
SendMessage("GameObject", "CheckURL", "facebook");
}
Hope this help!!!

Integrate Facebook Sign In in Intel XDK

hope that some body answer.. thanks in advance
I trying to integrate Facebook Sign In in Intel XDK but I only gets a blank screen and a button Cancel on top... any help here is my code
function facebook_login(){
document.addEventListener("intel.xdk.facebook.login",function(e){
if (e.success == true)
{
var facebookUserID = "me"; //me = the user currently logged into Facebook
document.addEventListener("intel.xdk.facebook.request.response",function(e) {
console.log("Facebook User Friends Data Returned");
if (e.success == true) {
var data = e.data.data;
var outHTML = "";
for (var r=0; r< data.length; r++) {
outHTML += "<img src='http://graph.facebook.com/"
+ data[r]["id"]
+ "/picture' info='"
+ data[r]["name"] + "' />";
}
alert(outHTML);
document.removeEventListener("intel.xdk.facebook.request.response");
}
},false);
}
else
{
console.log("Unsuccessful Login");
}
}, false);
intel.xdk.facebook.login("publish_stream, publish_actions, offline_access");
}
I'm not 100% sure but if you look at the end of this page : https://software.intel.com/en-us/html5/articles/integrating-facebook-functionality-into-hybrid-apps-using-the-intel-xdk
You'll see that you need to register your app through facebook and then build it.
Bye.
The intel.xdk.facebook library only works in the Legacy Builds that can be generated from the XDK IDE. It will not work in the XDK emulator, AppPreview, or Cordova Builds. Below is the forum link where IntelJohn points this out. I have confirmed this with independent testing.
https://forums.html5dev-software.intel.com/viewtopic.php?f=34&t=6444&sid=5b50fedfdfcb924a3f69579af01285c1
If your application will rely on any Cordova plugins (meaning you'll have to use the Cordova build) it would be better for you to drop use of the intel.xdk.facebook library and install the Cordova Facebook Plugin (https://github.com/Wizcorp/phonegap-facebook-plugin).

How to save a pdf file in iPhone memory and make it accessible by pdf file opener applications using titanium

i am new bie to titanium in my app i need to download and save a pdf file in iOS using titanium and the downloaded file can be accessible by third party pdf viewer applications.any help to achieve this thanks in advance.
1- Make sure your webservice returns a PDF file.
2- Use the FileSystem to manage your files
var xhr = Titanium.Network.createHTTPClient({
onload : function() {
var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'file.pdf');
f.write(this.responseData);
tmpFile = Ti.Filesystem.createTempFile();
var newPath = tmpFile.nativePath + "." + f.extension();
Ti.API.info("newPath: " + newPath);
tmpFile = Ti.Filesystem.getFile(newPath);
tmpFile.write(f.read());
},
timeout : 10000
});
xhr.open('GET', 'your webservice');
xhr.send();
Now you use a pdf viewer and open the PDF from the externalStorageDirectory
I tested on Android, it works !