I have 2 phonegap applications installed in my iPhone. I want to open one app from the other one.
I am able to load other app when I click the button on the current application.
Open
But I want to open the other app without a user action. One has to automatically invoke other one when some event like document.ready fires,
$(document).ready(function() {
$("#btnopen").click();
});
But the above code doesn't work. How can I invoke the other app using script & without a user action?
Could resolve the issue with below code,
$(document).ready(function() {
$("#btnopen").click();
$("#btnopen").bind("click",function() {
window.location= "mycoolapp://" ;
});
});
Related
I made an iOS app using Ionic Framework (https://appsto.re/cn/EY8s7.i). Is it possible to simulate user input to that app?
For example, user clicks QQ login button in my app, and my app opens the facebook authentication page inside the in-app browser. Now I want the app automatically fill the username and password to the authentication window and hit the "Login" button.
How can I achieve it?
I suppose you want to accomplish this to test your app and some of its functionalities?
If so, you should use Angular Protractor for this kind of testing.
Protractor is a Node.js program, and runs end-to-end tests that are also written in JavaScript and run with node. Protractor uses WebDriver to control browsers and simulate user actions.
Here's an example:
describe('TODO list', function() {
it('should filter results', function() {
// Find the element with ng-model="user" and type "jacksparrow" into it
element(by.model('user')).sendKeys('jacksparrow');
// Find the first (and only) button on the page and click it
element(by.css(':button')).click();
// Verify that there are 10 tasks
expect(element.all(by.repeater('task in tasks')).count()).toEqual(10);
// Enter 'groceries' into the element with ng-model="filterText"
element(by.model('filterText')).sendKeys('groceries');
// Verify that now there is only one item in the task list
expect(element.all(by.repeater('task in tasks')).count()).toEqual(1);
});
});
More info about this matter can be found at AngularJS end-to-end testing.
Is there a way to check iOS to see if another app has been installed and then launched? If memory serves me this was not possible in early versions but has this been changed?
Doable, but tricky.
Launching installed apps, like the FB or Twitter apps, is done using the Custom URL Scheme. These can be used both in other apps as well as on web sites.
Here's an article about how to do this with your own app.
Seeing if the URL is there, though, can be tricky. A good example of an app that detects installed apps is Boxcar. The thing here is that Boxcar has advanced knowledge of the custom URL's. I'm fairly (99%) certain that there is a canOpenURL:, so knowing the custom scheme of the app you want to target ahead of time makes this simple to implement.
Here's a partial list of some of the more popular URL's you can check against.
There is a way to find out the custom app URL : https://www.amerhukic.com/finding-the-custom-url-scheme-of-an-ios-app
But if you want to scan for apps and deduce their URL's, it can't be done on a non-JB device.
Here's a blog post talking about how the folks at Bump handled the problem.
There is a script like the following.
<script type="text/javascript">
function startMyApp()
{
document.location = 'yourAppScheme://';
setTimeout( function()
{
if( confirm( 'You do not seem to have Your App installed, do you want to go download it now?'))
{
document.location = 'http://itunes.apple.com/us/app/yourAppId';
}
}, 300);
}
</script>
Calling this script from the web (Try to start MyApp), you can determine if your app with scheme "yourAppScheme" is installed on the device or not.
The App will launch if it is installed on the device and "yourAppScheme" is registered in it.
If the app is not installed you can suggest the user to install this app from iTunes.
To check if an app is installed (e.g. Clear):
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"clearapp://"]];
To open that app:
BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"clearapp://"]];
Hides the error message if the app is not installed
At Branch we use a form of the code below--note that the iframe works on more browsers. Simply substitute in your app's URI and your App Store link.
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
window.onload = function() {
// Deep link to your app goes here
document.getElementById("l").src = "my_app://";
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
}, 500);
};
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
</body>
</html>
There's a second possibility that relies on cookies first and the javascript redirect only as a fallback. Here's the logic:
When a user without the app first taps on a link to your app, he or she is redirected straight to the App Store. This is accomplished by a link to your app actually being a dynamically-generated page on your servers with the redirect. You create a cookie and log a "digital fingerprint" of IP address, OS, OS version, etc. on your backend.
When the user installs the app and opens it, you collect and send another "digital fingerprint" to your backend. Now your backend knows the link is installed On any subsequent visits to links associated with your app, your servers make sure that the dynamically-generated redirect page leads to the app, not the App Store, based on the cookie sent up with the request.
This avoids the ugly redirect but involves a ton more work.
To my understanding, because of privacy issues, you can't see if an app is installed on the device. The way around this is to try and launch the app and if it doesn't launch to have the user hit the fall back url. To prevent the mobile safari error from occurring I found that placing it in an iframe helps resolve the issue.
Here's a snippet of code that I used.
<form name="mobileForm" action="mobile_landing.php" method="post">
<input type="hidden" name="url" value="<?=$web_client_url?>">
<input type="hidden" name="mobile_app" value="<?=$mobile_app?>">
<input type="hidden" name="device_os" value="<?=$device_os?>">
</form>
<script type="text/javascript">
var device_os = '<? echo $device_os; ?>';
if (device_os == 'ios'){
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100)
return;
document.forms[0].submit(); }, 5);
var redirect = function (location) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', location);
iframe.setAttribute('width', '1px');
iframe.setAttribute('height', '1px');
iframe.setAttribute('position', 'absolute');
iframe.setAttribute('top', '0');
iframe.setAttribute('left', '0');
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
};
setTimeout(function(){
window.close()
}, 150 );
redirect("AppScheme");
I struggled with this recently, and here is the solution I came up with. Notice that there is still no surefire way to detect whether the app launched or not.
I serve a page from my server which redirects to an iPhone-specific variant upon detecting the User-Agent. Links to that page can only be shared via email / SMS or Facebook.
The page renders a minimal version of the referenced document, but then automatically tries to open the app as soon as it loads, using a hidden <iframe> (AJAX always fails in this situation -- you can't use jQuery or XMLHttpRequest for this).
If the URL scheme is registered, the app will open and the user will be able to do everything they need. Either way, the page displays a message like this at the bottom: "Did the app launch? If not, you probably haven't installed it yet .... " with a link to the store.
I have to open my iOS app whenever user open a link of my app in browser. I have already used a like myApp:// but i want to open my app even when user open an http link a from browser. Just like pinterest. Pinterest opens app even if i open a regular http link like this http://www.pinterest.com/pseudoamber/ and using URL scheme as well like this pinterest://www.pinterest.com/pseudoamber/. My app is opening on myApp://www.myapp.com now i want to open my app when user open an http link like this http://www.myapp.com
Anybody please help
Here is an example using jQuery:
$(document).ready(function() {
var user_agent_header = navigator.userAgent;
if(user_agent_header.indexOf('iPhone')!=-1 || user_agent_header.indexOf('iPod')!=-1 || user_agent_header.indexOf('iPad')!=-1){
setTimeout(function() { window.location="myApp://www.myapp.com";}, 25);
}
});
This might be a easy question but i couldn't find solution. I want to open AppWorld by clicking a button in my BB application. For example when user clicks this button Appworld will show "Facebook Application" page. Can i do this?
In Android platform this line launches GooglePlay for Facebook App. Does BlackBerry supports this kind of method?
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.facebook.katana")));
Here is a simple way to do this:
Browser.getDefaultSession().displayPage("http://appworld.blackberry.com/webstore/content/2360/?lang=en");
Above code will invoke the browser in the application and open the BlackBerry App World, I tested it in device and it's perfectly working. For now I put a Whats App messenger link, but you can customize the link according to your requirement.
You can open App World from your BB application directly using the following code. This code avoids opening the browser first.
Registry registry = Registry.getRegistry(this.getClass().getName());
Invocation invocation = new Invocation(null, null,
"net.rim.bb.appworld.Content",
false, ContentHandler.ACTION_OPEN);
invocation.setArgs(new String[] { /* app id in appworld */ });
registry.invoke(invocation);
I have downloaded the file structure of my JQuery Mobile app. I have done this to test running it from the local file system. The reason why is I want my app to run with Cordova. From my understanding cordova runs files under file://. Currently, my file structure looks like this:
index.html
account
register.html
reset.html
In index.html, I have a "sign up" button. When someone clicks it, I use the following code:
$.mobile.changePage("account/register.html", { transition: "slide" });
I've verified that register.html works fine if i put the complete path in the browser url. Oddly, I see "error loading page" when I click "sign up". Is there some problem with using changePage under file://. If so, how do I overcome this?
Thank you!
try this
$.mobile.changePage("../account/register.html", { transition: "slide" });
You can just leave .. links in the code and it will work fine. Unless you have a reason to explicitly call changePage.
This answer is specificly if you run into an issue running the PhoneGap app on iOS.
Be sure you set the $.mobile.allowCrossDomainPages = true; which is required for AJAX calls to inject pages.
In your PhoneGap app object definition:
var app = {
initialize: function() {
// setting required to use $.mobile.changePage()
// http://jquerymobile.com/demos/1.2.0/docs/pages/phonegap.html
$.mobile.allowCrossDomainPages = true;
},
};
So when you call app.initialize() in your index.html, this property will be set prior to any $.mobile.changePage() function calls.
This will save you hours of trying to figure out the issue as no error is returned via the Safari Web Inspector.