[[__NSArrayM insertObject:atIndex:]: object cannot be nil] [Cordova-Ios] App crash with SSL pinned active
FranciscoVega2 opened this issue · comments
Hi, I'm having a problem similar to issue #173, but that one is closed. I hope you can help me, please.
Describe the bug
When I'm trying to make a POST request, my app crashes due to an NSException. This works fine on Android with the same code and .cer file.
System info
- affected HTTP plugin version: [3.3.1]
- affected platform(s) and version(s): [ iOS 14.2]
- affected device(s): [ iPhone 6 plus]
- cordova version: [11.1.0]
- cordova platform version(s): [ ios 6.3.0, android 10.1.2]
Minimum viable code to reproduce
const options = {
method: 'post',
data: { id: 12, message: 'test' },
headers: { Authorization: 'OAuth2: token' }
};
cordova.plugin.http.sendRequest('https://google.com/', options, function(response) {
// prints 200
console.log(response.status);
}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
I have the same problem, it happens to me sometimes not always, when I make a post request the ios app crash, on android it works fine.
I make the request as: http.post()
The problem may lie in the "setServerTrustMode" function. If I use the following code, there will be an error.
cordova.plugin.http.setServerTrustMode('pinned', function () {
cordova.plugin.http.get(url, $.extend(data, obj2), {}, function (response) {
console.log(response)
}, function (response) {
if (response.status != -7) {
alert(response.error);
}
});
}, function () {
showAlert('err');
});
If I use the following code, it can run normally.
cordova.plugin.http.get(url, $.extend(data, obj2), {}, function (response) {
console.log(response)
}, function (response) {
if (response.status != -7) {
alert(response.error);
}
});
However, I cannot determine if it's a problem with the certificate path or a plugin issue. I have tried placing the certificate in various paths, but the error still occurs.