Cannot find hostname in file:/// error when using Ionic and OAuth.io - angularjs

I am using Ionic and Oauth.io to perform authentication. If I run ionic serve and include the outh.js file in my index everything works good from the browser.
But when I run ionic run ios or install the app in android, I get the following error when I press the auth button (the one that suppose to execute OAuth.popup
I do not know what to do, until now I have checked the following:
In config.xml I have access, allow-intent and allow-navigation full permisive
I have installed and re-installed the plugin ionic plugin add https://github.com/oauth-io/oauth-phonegap.git
I tried to run the native app without the inclusion of the oauth.js file and everything breaks.
Using current versions up to date.
I am new to Ionic, so I don't know how to debug the device-running app or simulator.
Could be similar to this post but not exactly .
Your advices will be appreciated.

I figure it out reading some posts. The OAuth initialization and references should be done after the device is ready, so it is best to put the initialize in this block:
$ionicPlatform.ready(function() {
// ...
if(typeof window.OAuth !== 'undefined'){
$rootScope.OAuth = window.OAuth;
$rootScope.OAuth.initialize('XXX');
}
else{
console.log("plugin not loaded, this is running in a browser");
$.getScript( "lib/oauth.js", function() {
$rootScope.OAuth = OAuth;
$rootScope.OAuth.initialize('XXX');
});
}
});
Now, if the plugin is loaded it initializes the window.OAuth object, else the app is running in browser, so I have to include the oauth.js file. Also I assigned the OAuth to the $rootScope for quick access.
Hope this helps anyone.

Related

RNIap.getProducts(itemSku) returns empty array

I am using the package react-native-admob
I created an alpha track of my app and created a managed product on the play console
If I try
RNIap.prepare()
I get the error
RNIap.prepare is not a function. (In 'RNIap.prepare()', 'RNIap.prepare' is undefined)
if I try
const itemSkus = Platform.select({
ios: [
my_product_id
],
android: [
my_product_id
]
});
const products = await RNIap.getProducts(itemSkus);
console.log(products)
I get
Array []
Is there any additional setup I'm missing? This is my first time working with in-app-purchases on react-native
I have been following along with this tutorial, but run into problems when I get to RNIap.prepare(). My app was using the Expo managed workflow, and is now using the bare workflow. I am still running my app with expo start, because I don't know what else I can do to run it.
Have you followed these steps in the document rn-iap? This was the document which i followed and implemnted in app purchase for both android and ios in react native. It explains easily and beautifully. Do check it out.
ps: Even my app is in production and it has succesfull in app purchase
You can't get RNIap.prepare() in android before first release in Google Play Store
The answer was actually that I had a different bundle id for the app on the Google Play Console than I did in all my files. Expo chose this other bundle id for me as com.myAppName.
Because the play console does not allow you to change the bundle id I had to search for com.myAppName everywhere in my project and change it to the bundle id I had entered in on the google play console.
RNIap.prepare() is apparently not even a function anymore, but it is true that you must publish a release in the Google Play Store before enabling IAP, but you can publish a Beta.

UPI Deeplinking from IONIC to BHIM - Ionic1 (WebIntent)

Currently I am working on a Project which is implemented in Ionic 1 and AngularJs.
Now we are working to integrate it with BHIM UPI to perform In-App payment. I think we need to install IONIC Native Web Intent plugin in order to make web intent call to BHIM.
But I am fairly new to angularJs and Ionic. I have seen some of the questions related to this but those are implemented in Ionic3 and latest versions.
UPI Deeplinking from IONIC to GooglePay does not work as expected
DEEPLINK_HOST in ionic deeplink
Deeplinking - Opening an Ionic App through another Ionic App
I have tried to achieve this by making Web Intent calls with help of this https://www.npmjs.com/package/#ionic-native/web-intent?activeTab=readme but with no luck. It's giving Error message like below
ionic.bundle.min.js:150 Error: [$injector:unpr] http://errors.angularjs.org/1.5.3/$injector/unpr?p0=webIntentProvider%20%3C-%20webIntent%20%3C-%20PaymentComponent%20%3C-%20PaymentComponent
at http://localhost:8100/js/ionic.bundle.min.js:40:416
at http://localhost:8100/js/ionic.bundle.min.js:77:7
at Object.d [as get] (http://localhost:8100/js/ionic.bundle.min.js:74:270)
EDIT :
I want to open BHIM UPI app from my Ionic App and able return success or failure status of transaction.
Any help or directions to achieve this will be highly appreciated.
There is no 'webIntentProvider' exists in ionic providers.
You've to remove 'webIntent' from your controllers injections. And use below code to open existing UPIs available in your mobile.
window.plugins.intentShim.startActivity(
{
action: window.plugins.intentShim.ACTION_VIEW,
url: urlIntent
},
function () { },
function () {
alert('Failed to open URL via Android Intent')
}
);
It'll show all available UPI providers which are installed in your mobile. Please go through documentation Deeplinking UPI for more details.
Cross check your package.json & confilg.xml, whether you installed above plugin in your app or not.

Cannot GET index.html Azure Linux Web App

We created a Linux Web App in Microsoft Azure. The application is static written with React (html and Javascript).
We copied the code into the wwwroot folder, but the application only showing only hostingstart.html and when we try to get page index.html we have this error:
Cannot GET /index.html
We tried with a sample of Azure in GitHub (https://github.com/Azure-Samples/html-docs-hello-world) but the error is the same.
The url is this: https://consoleadmin.azurewebsites.net/index.html
Last week the application was running correctly.
We forget to do something?
MAY 2020 - You don't have to add any javascript files or config files anywhere. Let me explain.
I was facing this exact same issue and wasted 6 hours trying everything including the most popular answer to this question. While the accepted answer is a nice workaround (but requires more work than just adding the index.js file), there's something a simpler than that.
You see, when you just deploy an Azure Web App (or App Service as it is also called), two things happen:
The web app by default points to opt/startup/hostingstart.html
It also puts a hostingstart.html in home/site/wwwroot
When you deploy your code, it replaces hostingstart.html in home/site/wwwroot but the app is still pointing to opt/startup/hostingstart.html. If you want to verify this, try deleting opt/startup/hostingstart.html file and your web app will throw a "CANNOT GET/" error.
So how to change the default pointer? It's simpler than it looks:
Go to Configuration tab on your web app and add the following code to startup script:
pm2 serve /home/site/wwwroot --no-daemon
If this web app is a client-side single-page-app and you're having issues with routing, then add --spa to the above command as follows:
pm2 serve /home/site/wwwroot --no-daemon --spa
This will tell the web app to serve wwwroot folder. And that's it.
Image for reference:
Screenshot explaination
PS: If you only set the startup script without deploying your code, it will still show the hostingstart.html because by default that file lies in the wwwroot folder.
Ok you are gonna love this. This happened to me today also. Same exact thing.
I am pretty sure the azure team flipped a switch somewhere and we fell through a crack.
I found this obscure answer with no votes and it did the trick (with a little extra finagling)
BONUS! this also fixed my router issues I was having only on the deployed site (not local):
Credit: #stormwild: Default documents not serving on node web app hosted on Azure
From #stormwild's post see here:
https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#NodeHome
Steps:
Go to your azure portal, select your app service and launch ssh
In ssh terminal, navigate via command line to /home/site/wwwroot
create index.js there with the following code:
var express = require('express');
var server = express();
var options = {
index: 'index.html'
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);
NOTE: Be sure to run npm install --save express also in this folder else your app service will crash on startup
Be sure to restart your app service if it doesn't do so automagically
A workaround, I changed the webapp stack to PHP 7
Another solution would be to add a file called ecoysystem.config.js right next to your index.html file.
module.exports = {
apps: [
{
script: "npx serve -s"
}
]
};
This will tell pm2 to associate all requests to index.html as your app service starts up.
Very helpful information here: https://burkeholland.github.io/posts/static-site-azure/

Ionic Push on Android: unexpected error occured

I'm trying to use Ionic Push notifications on android, but every time I got the following error:
Ionic Push:, (debug) unexpected error occured.
Ionic Push:, [object Object]
I'm using Genymotion as my emulator, with Google Play Services installed (https://stevenkideckel.wordpress.com/2014/12/27/how-to-install-google-play-services-on-genymotion/). Testing on a real device is not working as well.
Also, I'm using this push plugin (https://github.com/phonegap/phonegap-plugin-push), and installed like this:
ionic plugin add phonegap-plugin-push --variable SENDER_ID="my-gcm-project-number"
My push code look's like this:
var push = new Ionic.Push({
'debug': true,
'pluginConfig': {
'android': {
'senderID': 'my-project-number',
'iconColor': '#343434'
}
}
});
push.register(function(token) {
console.log('Device token:', token.token);
push.saveToken(token);
});
I already configured my Ionic app using:
ionic config set dev_push false
ionic push --google-api-key my-google-api-key
ionic config set gcm_key <my-gcm-project-number>
I tried to search for similar problemas but never found a solution.
Anyone can help me?
Thanks!
To answer my own question:
When I published my app and testing on a real Android device downloading the app from Google Play, it worked.
A few things to try if you are getting this problem:
Remove and add again the push plugin:
ionic plugin remove phonegap-plugin-push
ionic plugin add phonegap-plugin-push --variable SENDER_ID="my-gcm-project-number"
Also:
Generate a new project number and API key on Google Console;
Check .io-config.json to check if your keys and numbers are correct;
Make sure your dev push is off: ionic config set dev_push false;
Set your GCM key on Ionic IO: ionic config set gcm_key <your-gcm-project-number>;
Check (and make it again if needed) your build profiles on Ionic IO;
Also check this answer: https://forum.ionicframework.com/t/ionic-push-not-working-on-android/52636/2
Hope this help someone.

Not getting token from ionic push.register when debug mode is false

I am implementing push notification in my ionic app.
I have setup initial steps successfully. In mu debug mode When I use this code:
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
}
});
push.register(function(token) {
alert("Hello");
console.log("Device token:",token.token);
});
});
I have already run this command:
ionic config set dev_push true
I am getting device token value and receiving push successfully.
But when I run this command
ionic config set dev_push false
and put "debug": true, I am not receiving any token.
I have successfully uploaded the .p12 file in Online Acccount of ionic.
If you set dev_push false. You won't get a notification.
Reason.
The variable is named as development_push meaning it is to be used in development mode only. Which means you are on a laptop/PC and testing the API in development mode. But if you switch to, development_push = false then it means you ain't testing on a system anymore and you need to put that .apk or ios equivalent in your phone and test it out in the real world.
So If I were you.
I would set it to false
Build my application.
and install the app in my phone.
and see if it works.
Hope it helps
After spending one complete day. I found one simple solution.
I don't know whether it will work for others or not. But still I am posting may be it helps someone.
After changing:
ionic config set dev_push true
to
ionic config set dev_push false
You have to first remove the Platform whether it is iOS/Android.
ionic platform rm ios/androind
Then add again and build your project. Now it will work for sure.
ionic platform add ios/android
ionic build ios/android

Resources