Hello,
I got an error when using the ionic native http to make backend calls, the app crashes down when making a login call on ios device. But the same works with angular http.
AFURLRequestSerialization.m
Signal SIGABRT (mutableRequest setValue ….)
#pragma mark - AFURLRequestSerialization
- (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
withParameters:(id)parameters
error:(NSError *__autoreleasing *)error
{
NSParameterAssert(request);
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[self.HTTPRequestHeaders enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL * __unused stop) {
if (![request valueForHTTPHeaderField:field]) {
[mutableRequest setValue:value forHTTPHeaderField:field];
}
}];
__block_literal_4 * 0x1b233ce88 0x00000001b233ce88
field NSTaggedPointerString * @"method" 0xa00646f6874656d6
value NSNull * 0x1b2346650 0x00000001b2346650
stop BOOL * NO 0x000000016af41a50
request NSMutableURLRequest * 0x1c400e850 0x00000001c400e850
mutableRequest NSMutableURLRequest * 0x1c400e870 0x00000001c400e870
NSURLRequest NSURLRequest
NSObject NSObject
isa Class NSMutableURLRequest 0x000021a1b234ed09
_internal NSURLRequestInternal * 0x1c400e860 0x00000001c400e860
NSObject NSObject
isa Class NSURLRequestInternal 0x000001a1b234ec91
request _CFURLRequest * 0x1c41b3780 0x00000001c41b3780
[NSNull length]: unrecognized selector sent to instance 0x1b2346650
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1b2346650'
*** First throw call stack:
(0x1810e6364 0x18032c528 0x1810f3828 0x1810ebd10 0x180fd0ecc 0x18184e04c 0x18172f3dc 0x1816c6dd4 0x100f5daf0 0x181124fa8 0x100f5d4b0 0x100f5baf4 0x100f533ac 0x100f52224 0x100f4a5fc 0x100f8d244 0x100f117f4 0x100f11658 0x100f13238 0x190473130 0x190407a30 0x190409c10 0x1901f4148 0x1903d1800 0x1901b474c 0x1901b7140 0x1883d4d38 0x1883d4ff8 0x18108e97c 0x18108e8fc 0x18108e184 0x18108bd5c 0x180fabe58 0x182e58f84 0x18a62b67c 0x100f08320 0x180ac856c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
package.json
{
"name": "XXX",
"version": "XXX",
"author": "XXX",
"private": true,
"config": {
"ionic_webpack": "./config/webpack.config.js"
},
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.4.6",
"@angular/compiler": "4.4.6",
"@angular/compiler-cli": "4.4.6",
"@angular/core": "4.4.6",
"@angular/forms": "4.4.6",
"@angular/http": "4.4.6",
"@angular/platform-browser": "4.4.6",
"@angular/platform-browser-dynamic": "4.4.6",
"@ionic-native/core": "4.4.2",
"@ionic-native/http": "^4.5.2",
"@ionic-native/splash-screen": "4.4.2",
"@ionic-native/status-bar": "4.4.2",
"@ionic/storage": "^2.1.3",
"@ngx-translate/core": "^7.2.2",
"@ngx-translate/http-loader": "^2.0.0",
"angular2-cookie": "^1.2.6",
"cordova-browser": "^4.1.0",
"cordova-ios": "^4.5.4",
"ionic-angular": "3.9.2",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "^5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@angular/cli": "^1.5.5",
"@ionic/app-scripts": "3.1.2",
"typescript": "2.3.3"
}
}
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="XXX" version="XXX" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>XXX</name>
<description>XXX</description>
<author email="XXX">XXX</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<allow-navigation href="http://*/" />
<allow-navigation href="http://localhost:8100/*" />
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<icon height="57" src="resources/ios/icon/icon.png" width="57" />
<icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
<icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
<icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
<icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
<icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
<icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
<icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
<icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
<icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
<icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
<icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
<icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
<icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
<icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
<icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
<icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
<icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
<icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
<splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
<splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
<splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
<splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
<splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
<splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
<splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
<splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
<splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
<splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
<splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
<splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
<splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
</platform>
<plugin name="ionic-plugin-keyboard" spec="~2.2.1" />
<plugin name="cordova-plugin-whitelist" spec="1.3.1" />
<plugin name="cordova-plugin-device" spec="1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.11" />
<plugin name="cordova-plugin-advanced-http" spec="1.9.0" />
</widget>
Here is my code how I using the native http call
@Injectable()
export class HttpNativeProvider {
constructor(private http: HTTP) {
}
public callLogin(){
let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});
let options = new RequestOptions({headers: headers, withCredentials: true});
let params: URLSearchParams = new URLSearchParams();
params.set('target', 'XXX');
params.set('username', XXX);
params.set('password', XXX);
return this.post(XXX, params, options)
.map(this.returnData)
.catch(this.handleError);
}
private post(url, params?: any, options: any = {}) {
let responseData = this.http.post(url, params, options);
return Observable.fromPromise(responseData);
}
private returnData(res: Response) {
if (JSON.stringify(res.text()).indexOf('error') === -1) {
return res || {};
} else {
throw {message: 'Error occured in Login' + res};
}
}
private handleError(error: any) {
return Observable.throw(error.message);
}
}