응용 프로그램이 이 아니고이면 "실행 가능한 알림"버튼을 클릭 한 후 다음 코드를 실행합니다 .i 백그라운드 모드, 원격 알림을 활성화했습니다.NSURLSessionDataTask 호출이 목표 C에서 작동하지 않습니까?
//base url is changed for privacy purpose
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/engine/auth/tx", [SharedData getGatewayURL]]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:HTTP_REQUEST_TIME_OUT];
[request setHTTPMethod:@"POST"];
NSString *encodedXML = [encrypted urlEncodeUsingEncoding:NSUTF8StringEncoding];
NSString *params = [NSString stringWithFormat:@"%@=%@", REQUEST_PARAMETER_NAME, encodedXML];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//Handle response
}];
[postDataTask resume];
// 위임
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
if([challenge.protectionSpace.host isEqualToString:@"211.23.34.234"]){
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
}
}
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSData *data = [NSData dataWithContentsOfURL:location];
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes {
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
}
우리는 응용 프로그램이 일시 중단 또는 종료 될 때 백그라운드 작업을 실행하기위한 NSURLSessionDataTask를 사용할 수 (I 실제되지 데모 서버 URL이 여기에 표시 한) ?
이 코드는 에 완벽하게 작동합니다. 서버 URL은입니다. https://211.23.34.234/engine/auth/tx
하지만 난 작동하지 서버 URL https://demo.tes.com/engine/auth/tx에 변경할 때.
NSURLSessionDataTask의 문제점은 무엇입니까?
고정 IP 211.23.34.234? 왜 같은 코드가 https://demo.tes.com/engine/auth/tx과 작동하지 않습니까? (이 서버 URL은 동적으로 바뀔 수 있습니다.) 어떤 도움을 주시면 감사하겠습니다.
해결 방법?
참고 : : 설정 위임 NSURLSessionDataTask의 "무기 호"https://demo.tes.com/engine/auth/tx 서버 작동하지만 https://211.23.34.234/engine/auth/tx
방법은 모두 서버에서 작동하도록하지에?
받고있는 응답 데이터는 무엇입니까? – Suresh
서버에서 응답이 없습니다. 앱이 닫히면 다시 돌아옵니다. –
@RonakChaniyara. 링크는 데모이며 개인 정보 보호 목적으로 표시되지 않습니다. –