测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2014年12月 |
由 未声明 维护。
依赖项 | |
AFNetworking | = 1.2.1 |
Reachability | = 3.1.0 |
SBJson | = 3.2 |
MGTimelineManager 使用 AFNetworking 和 SBJson 解析和获取时间线。推文存储在 MGTweetItems 中。
查看示例以获取完整代码和可视示例
#import "MGTimelineManager.h"
//twitter ids are more stable b/c twitter usernames can change, ids cannot
//head to http://www.idfromuser.com/ to lookup twitter IDs!
MGTimelineManager *timelineManager = [[MGTimelineManager alloc] initWithTwitterIDs:[NSArray arrayWithObjects:@"63400533", @"486599947", nil]];
timelineManager = self;
[timelineManager fetchTimelines];
以下是 MGTimelineManagerDelegate 方法的一个示例用法
#pragma mark - MGTimelineManagerDelegate methods
- (void) timelineManagerLoadedNewTimelines:(NSDictionary *)timelines
{
[tableView reloadData];
}
//timeline will be nil if no new tweets were found
- (void) timelineManagerLoadedNewTweets:(NSArray *)timeline forTwitterID:(NSString *)twitterID
{
NSLog(@"Timeline loaded for id - %@",twitterID);
}
- (void) timelineManagerConnectionError:(MGTimelineManager *)timelineManager
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Could not connect to twitter" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
}
- (void) timelineManagerErrorLoadingTimelineForTwitterID:(NSString *)twitterID
{
NSString *message = [NSString stringWithFormat:@"Could not load twitter id - %@",twitterID];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:message delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
}
//OPTIONAL
//Use MGTimelineSaveUtil to save json timelines
//could be useful to load up saved timelines instead of loading new timelines on every startup
- (void) timelineManagerLoadedJSONTimeline:(NSArray*)jsonTimeline forTwitterID:(NSString*)twitterID {
[MGTimelineSaveUtil saveTimeline:jsonTimeline forTwitterID:twitterID];
}
可选:如果您有任何保存的 json 时间线,也可以从 MGTimelineSaveUtil 加载保存的时间线(有关保存 json 时间线的详细信息,请参阅 timelineManagerLoadedJSONTimeline: 代理方法)
//makes sure there is at least one timeline saved
if ([MGTimelineSaveUtil amountOfTimelinesSavedForTwitterIDs:[self twitterIDs]] > 0) {
[timelineManager loadSavedTimelinesForTwitterIDs:[self twitterIDs]];
}else {
[timelineManager fetchTimelines];
}