mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
private post method added to the iOS web client
This commit is contained in:
@ -69,4 +69,32 @@ export class Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static post(url: string, postData: string, successCallback?: (result: any) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
var sessionConfig = Foundation.NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = Foundation.NSOperationQueue.mainQueue();
|
||||
var session = Foundation.NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
|
||||
|
||||
var urlRequest = Foundation.NSMutableURLRequest.requestWithURL(Foundation.NSURL.URLWithString(url));
|
||||
urlRequest.setHTTPMethod("POST");
|
||||
urlRequest.setHTTPBody(Foundation.NSString.initWithString(postData).dataUsingEncoding(4));
|
||||
|
||||
var dataTask = session.dataTaskWithRequestCompletionHandler(urlRequest, function (data, response, error) {
|
||||
if (error) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new Error(error.localizedDescription()));
|
||||
}
|
||||
} else if (successCallback) {
|
||||
successCallback(data);
|
||||
}
|
||||
});
|
||||
|
||||
dataTask.resume();
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
declarations.ios.d.ts
vendored
7
declarations.ios.d.ts
vendored
@ -60,7 +60,8 @@ declare module Foundation {
|
||||
}
|
||||
|
||||
export class NSString {
|
||||
static initWithDataEncoding(data: any, encoding: any) : any;
|
||||
static initWithDataEncoding(data: any, encoding: any): any;
|
||||
static initWithString(source: string): any;
|
||||
}
|
||||
|
||||
export class NSURLSessionConfiguration {
|
||||
@ -78,6 +79,10 @@ declare module Foundation {
|
||||
export class NSURL {
|
||||
static URLWithString(url : string): any;
|
||||
}
|
||||
|
||||
export class NSMutableURLRequest {
|
||||
static requestWithURL(url: any): any;
|
||||
}
|
||||
}
|
||||
|
||||
declare module QuartzCore {
|
||||
|
Reference in New Issue
Block a user