gpt4 book ai didi

ios - 使用 RSSParser 进行 Today 扩展小组件

转载 作者:行者123 更新时间:2023-11-29 02:04:02 25 4
gpt4 key购买 nike

我正在尝试从 RSS URL 获取最新数据并在 Today Widget 扩展中显示其内容,使用 RSSParser 但问题是它返回 null !这是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];

NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://myBlog.net/?feed=rss2"]];
[RSSParser parseRSSFeedForRequest:req success:^(NSArray *feedItems) {

[self setDataSource:feedItems];

} failure:^(NSError *error) {
[self setTitle:@"Error"];
NSLog(@"Error: %@",error);

}];

item = [self.dataSource objectAtIndex:0];

//this returns null:
NSLog(@"Title is %@",[item title]);

NSLog(@"Widget Runs");

}

最佳答案

不熟悉该库,但调用模式足够熟悉,可以假设请求异步运行。这意味着代码从上到下执行的正常假设并不成立。

- (void)viewDidLoad {
[super viewDidLoad];

NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://myBlog.net/?feed=rss2"]];
[RSSParser parseRSSFeedForRequest:req success:^(NSArray *feedItems) {
// this runs after the request completes
NSLog(@"Got here #2");

// moving your test code here will allow it to work
item = [self.dataSource objectAtIndex:0];
NSLog(@"Title is %@",[item title]);

} failure:^(NSError *error) {
[self setTitle:@"Error"];
NSLog(@"Error: %@",error);

}];

// this runs before the request begins
NSLog(@"Got here #1");
}

关于ios - 使用 RSSParser 进行 Today 扩展小组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30007201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com