0
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//call 2 web service here.
[self jsonParser:jsonData];
completionHandler(UIBackgroundFetchResultNewData);
}
-(void)jsonParser:(NSData *)data
{
//[downloader downloadXMLContentsFromURL:actualURL withXML:encrypted];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:actualURL]
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)
{
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error:nil];
}];
[postDataTask resume];
//Here call to other service not shown
}
我已啓用「背景提取」從功能也是「遠程通知」稱這種方法
我是否需要實現這個方法?
- (void)application:(UIApplication *)application performFetchWithCompletionHandler: (void (^)(UIBackgroundFetchResult))completionHandler
這個工作正常,當應用程序處於活動狀態。但不工作的應用程序是在背景和Closed.same時間,當我打開應用程序它工作正常。我想在後臺運行服務時,應用程序關閉。如何解決這個問題?任何幫助將不勝感激。
像魅力工作..感謝您的答案。 –