我在 Xcode 中收到此警告
警告:尝试使用不在框架中的块创建 USE_BLOCK_IN_FRAME 变量。
Xcode 将我重定向到我的 NSStream
_naturStream = [[NSInputStream alloc] initWithData:natur];
出现此错误时是随机的,并且我的应用程序在触发时崩溃。有人试过类似的问题吗?
谢谢
编辑
在 appDelegate.h
@property (nonatomic, strong) NSInputStream *naturStream;
在 appDelegate.m 中:
NSData *natur = [NSData dataWithContentsOfURL:[NSURL URLWithString:_locString]];
_naturStream = [[NSInputStream alloc] initWithData:natur];
[_naturStream open];
if (_naturStream) {
NSError *parseError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithStream:_naturStream options:NSJSONReadingAllowFragments error:&parseError];
if ([jsonObject respondsToSelector:@selector(objectForKey:)]) {
for (NSDictionary *natur in [jsonObject objectForKey:@"results"]) {
_poi = [[POI alloc]init];
[_poi setTitle:[natur objectForKey:@"title"]];
[_poi setLat:[[natur objectForKey:@"lat"]floatValue]];
[_poi setLon:[[natur objectForKey:@"lng"]floatValue]];
[_poi setDistance:[natur objectForKey:@"distance"]];
[_poi setWebUrl:[natur objectForKey:@"webpage"]];
[_naturArray addObject:_poi];
}
}
}
else {
NSLog(@"Failed to open stream.");
}
[_naturStream close];
}
我意识到我忘了[_naturStream close]
我不知道它是否解决了问题?
编辑
另一件事,....我使用线程来获取 JSON 数据:
dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);
// execute a task on that queue asynchronously
dispatch_async(jsonParsingQueue, ^{
[self parseJSON];
dispatch_async(dispatch_get_main_queue(), ^{
[_kortvisning updateAnno];
[visListe updateList];
});
});
// release the dispatch queue
dispatch_release(jsonParsingQueue);