POST http calls not working in Ionic iOS build - ios

I've made an application in Ionic V4 and then build the same using cordova plugin (not capacitor). First page of my application is login where I'm getting values from form fields and sending it to login method where I am making a POST call to server.
loginUrl = 'http://localhost:3000/login';
errorLog: any;
login(form) {
const user = form.values;
this.httpClient.post(this.loginUrl, user).subscribe( response => {
this.toastController.create({message:'Login Successful', duration: 1000}).then(toast=> toast.present());
}, error => {
this.errorLog = error;
this.toastController.create({message:'Some Error Occured', duration: 1000}).then(toast=> toast.present());
})
}
Also I'm printing that error log in login page because once we make build, its hard to debug in device using Android Studio or Xcode.
So I'm printing error log like this
<h3>{{errorLog | json}}</h3>
I'm not getting error from POST call in case of running the application in web browser as well as in android. Getting error in iOS when I tried to make build and using Xcode, deployed into my iPad.
It's working fine in GET HTTP calls because previously I've tested GET HTTP calls in same but not working in POST HTTP calls.
Its returning 500 internal server error. Error object looks like
{
"statusText": "OK",
"status": 500,
"url": "http://localhost:3000/login",
"ok": false,
"name": 'HttpErrorResponse',
"message": "Http failure response for http://localhost:3000/login: 500 OK",
...
}
How I make build is
ionic build --prod --release
ionic cordova platform remove ios (if platform already exist).
ionic cordova platform add ios
ionic cordova prepare ios
Then I open the same ios folder into Xcode, select the developer account, connect my iPad and run it.

Were you able to resolve it?
I faced similar situation and here's how I got around it.
In capacitor.config.json file we need to specify 'server' from where we are getting the Api data.
"appId": "com.yoursite",
"appName": "Your Site",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"cordova": {},
//This part mentioned below is important.
"server": {
"url": "https://yoursite.com",
"allowNavigation": ["yoursite.com", "*.yoursite.com"]
},
Hope this helps.

Related

Using Firebase Authentication from iOS 7.1.2 Safari

I see this error:
Error: This operation is not supported in the environment this
application is running on. "location.protocol" must be http, https or
chrome-extension and web storage must be enabled.
When I use:
firebase.auth().signInWithPopup(provider)
.then(function(result) {
console.log(result);
})
.catch(function(error) {
console.log('popup', error);
//webSettings.setDomStorageEnabled(true);
firebase.auth().signInWithRedirect(provider)
.then(function(result) {
console.log(result);
})
.catch(function(error) {
console.log('redirect', error);
firebase.auth().signInAnonymously().catch(function(error) {
console.log('anonymous', error);
});
});
});
The first two login attempts via popup and redirect fail. It seems to happen only on iOS Safari.
I see others reporting the issue with Cordova, but I don't see an answer and I'm only using web and firebase. Not Cordova or ionic etc.
The anonymous login works on iOS but that is only a test and not what we want to use to use.
If you want to test it you can use https://meetup-reporter.firebaseapp.com/ from Safari on iOS
An example dump of the error object from the returned Promise is:
{"code": "auth/operation-not-supported-in-this-environment",
"constructor": function (a, b)
{this.code="auth/"+a;this.message=b||Xf[a]||"";}, "F": function ()
{return{code:this.code,message:this.message}}, "line": 44, "message":
"This operation is not supported in the environment this application
is running on. \"location.protocol\" must be http, https or
chrome-extension and web storage must be enabled.", "sourceURL":
"https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js",
"stack":
"https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:44:638\nhttps://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:45:258\nA#https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:44:545\nD#https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:45:242\nsignInWithPopup#https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:241:48\na#https://meetup-reporter.firebaseapp.com/__/firebase/4.1.2/firebase-auth.js:260:432\nhttps://meetup-reporter.firebaseapp.com/scripts/main.js:430:36",
"toJSON": function () {var
a=Array.prototype.slice.call(arguments);a:{var
e=Array.prototype.slice.call(a);var l=0;for(var
n=!1,C=0;Cl||l>=fk.length)throw new N("internal-error","Argument
validator received an unsupported number of arguments.");e=fk[l]+"
argument "+(e.name?'"'+e.name+'" ':"")+"must be "+e.N+".";break
a}e=null}}if(e)throw new N("argument-error",d+" failed: "+e);return
b.apply(this,a);}}
signInWithRedirect actually works in Cordova now: https://firebase.google.com/docs/auth/web/cordova
signInWithPopup and signInWithRedirect should also work for iOS7 and up. I just tested both on an iOS 7 device and they both work. What you are experiencing is likely to the fact that you are using this operation in Safari Private/Incognito mode where web storage is disabled. These operations depend on web storage in order to securely communicate the OAuth result to the parent page. You will need to ask your users to switch to regular mode when this happens, or you can use the Google Sign-in JS SDk to get the OAuth credential and then signInWithCredential. I think it may work in incognito mode.

OneSignal iOS SDK send notification fail Code 400

What I have done:
I have created a simple iOS native App which has nothing but OneSignal initializaion codes. I installed my App on my 2 devices, device A and device B. Both devices are subscribed to my OneSignal App Console. When I send a notification from OneSignal Web Console, the 2 devices can both recive the notification.
What I want to do:
When I click on a button on device A, device A will send a notification to device B.
What is the problem:
I followed the OneSignal iOS SDK document and created the following function
https://documentation.onesignal.com/docs/ios-native-sdk#section-sending-notifications
func onButtonClick() {
OneSignal.postNotification(
[
"contents": ["en": "Test Message"],
"include_player_ids": ["c00bb8a6-79da-419b-9999-e919831a5223"] // id of device B
],
onSuccess: {(result) in print("success") },
onFailure: {(error) in print("error : \(error)") }
)
}
however, when I clicked the button, an error shows up in the xCode debug console:
2017-01-20 11:15:52.702852 my.bundle.id[2263:1201122] ERROR: Create notification failed
error : Optional(Error Domain=OneSignalError Code=400 "(null)" UserInfo={returned={
errors = (
"Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."
);
reference = (
"https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"
);
}})
I was confused, because according to the OneSignal Reference document, send notification with "include_player_ids" Does not require API Auth Key.
https://documentation.onesignal.com/reference#create-notification
And it also says: NEVER use your 'REST API key' in client code, it is intended for use on your system or server only.
So what does this error mean? And what should I do?
I even copied and run this "work without any problems" code from this discussion, but the same Authorization error still shows up. What am I doing wrong?
The Answer
Just upgrade the SDK and the problem will be gone.
This was a bug in OneSignal-iOS-SDK 2.3.1, this bug was fixed in 2.3.2.
Please see their Github Release Notes.
How to avoid this kind of problems
Always run pod repo update before pod install to ensure that the pod install the latest version of the frameworks.
Thanks Kevin, Jason and Josh from One Signal Conversations to help me solve this problem.

Using Cordova and Phonegap Push Plugin get invalidRegistration on app server when push to iOS

I used this instruction on Google Cloud Messaging site to set certificates for APNS. I'm on development phase and set only development certificate in Apple Developer Console.
Then I set up phonegap-plugin-push and initialized it in JS like that (on deviceready of course):
var pushController = PushNotification.init({
"android": {
"senderID": "_",
"forceShow": true
},
"ios": {
"alert": "true",
"badge": "true",
"sound": "true"
}
});
pushController.on('registration', function (data) {
console.log("Push registration", data);
});
So when registration is successful I see registration id of the device in console. But when I try to push message from server to this registration id I get error response with code invalidRegistration. I'm pushing from node.js server with gcm package.
Same setup works great on Android. I wasn't sure about correctness of certificates and repeated process strictly following instructions. But result on iOS is the same.
As it heppens best way to solve the problem is to recheck every stage of process 100th time. The problem was in server side sertificate. It wasn't the same as the one that app and apns used.
Now I have problem with ad hoc production version but that's another story.

Ajax POST requests loosing payload in sencha app + phonegap

I'm developing a sencha web application with sencha touch 2.1.x
This app needs to run on a web server and as well as an iOS app, packaged with phonegap 3.1.
The web server version works well, but I'm facing some problems in the iOS version, when executing Ajax POST requests. This is a sample code:
var jsonParams =
{
"username": loginParams.user,
"password": loginParams.pwd,
"serverVersion": serverVersion
};
var jsonStr = JSON.stringify(jsonParams);
console.log(jsonStr);
Ext.Ajax.request({
url: internalRoute.LOGIN,
headers: {'Content-Type':'application/json'},
method: 'POST',
scope:this,
params: jsonStr,
success: function(response){
.....
},
failure: function(response) {
.....
},
});
Sometimes this requests works fine from the iOS version packaged with phonegap, but randomly it fails, because the post payload is empty. The console.log(jsonStr) prints the correct data, but the server receives no data. I also used an HTTP sniffer to capture the sent package, and it contains no POST payload.
Changed the code to user jQuery $.ajaxinstead of Ext.Ajax.request, and the problem persists.
Any idea of what can be wrong?
Thx
Looks like it's actually a proxy issue, nothing to do with sencha or phonegap.
If I deactivate the proxy, I don't get other external resources, but this issue never happens.
Will search how to fix the proxy issue.
Thanks

blackberry 6-7 environment failed at WL.Client.connect

i create a fresh new worklight (5.0.6) project with jquerymobile (1.2.0), add the blackberry 6-7 environment, nothing else.
here is the wlcommoninit code.
function wlCommonInit(){
WL.Client.connect({
onSuccess: onConnectSuccess,
onFailure: onConnectFailure
});
}
function onConnectSuccess(){alert("ok");}
function onConnectFailure(){alert("ko");}
i get the following issue when i preview the app.
wlclient init started worklight.js:1118
before: app init onSuccess worklight.js:1118
Request [/apps/services/api/cm2/blackberry/init] worklight.js:1118
after: app init onSuccess worklight.js:1118
wlclient init success worklight.js:1118
Failed to load resource: the server responded with a status of 403 (Forbidden)
`http://localhost:8080/apps/services/api/cm2/blackberry/init`
[/apps/services/api/cm2/blackberry/init] failure. state: 403, response: undefined worklight.js:1118
the common environment works fine.
am i missing something ?
thanks for your help
There is a known defect when previewing the BlackBerry 6-7 (and also Windows Phone); there is improper handling of the 403 status response (it's OK to get it, but the handling mishandles it...).
The app should work correctly on an actual device (probably simulator as well).

Resources