objective-c - URL applicationWillTerminate Objective-C

标签 objective-c

我一直在尝试在 de applicationWillTerminate 事件中执行或请求一个 url,但是当我这样做时,其他功能,如:

- (NSURLRequest *)connection:(NSURLConnection *)connection
             willSendRequest:(NSURLRequest *)request            redirectResponse:(NSURLResponse *)redirectResponse {
  [baseURL autorelease];
  baseURL = [[request URL] retain];
  return request;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  [responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  [responseData appendData:data];
}

它们没有被执行,我猜是因为最后执行的函数或事件是 applicationWillTerminate。有没有办法达到或做到这一点。

最佳答案

我昨天遇到了同样的问题,并使用下面的代码片段解决了它:

NSURLResponse* response = nil;
NSString* requestUrlString = <your URL>;
NSMutableURLRequest *syncRequest  = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
[NSURLConnection sendSynchronousRequest:syncRequest returningResponse:&response error:nil];

关于objective-c - URL applicationWillTerminate Objective-C ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9434657/

相关文章:

iphone - Objective-C 访问数组

iOS设置TableView展开TableCell的高度

ios - 保存或加载图像时 iPhone 设备的响应时间很慢

ios - 当我为 AFNetworking 设置我的 downloadProgressBlock 时,它只会在最后调用一次

ios - 没有 EXC_BAD_ACCESS 不能使 viewController 透明

ios - 无法从核心数据中获取特定列

ios - 当用户在 iOS 11 中点击时,UItextview 选择的文本不会被取消选择

当网络连接较差时,iOS 应用程序在启动时会挂起一段时间

IOS 无法为查询编译语句

iphone - 如何在iPhone的手机上显示倒数计时器?