仿鳳凰FM
iOS客戶端是出于3個目的

鳳凰FM的http請求返回數據為JSON格式,可以用Chalse輕松抓取到這些http請求,具體的請求信息在FenghuangFM/HTTPRequest下邊。
http請求返回為JSON格式的數據,解析JSON用到了MJExtension庫,JSON中有list時,使用如下方式告知JSON中key為"audiolist"的list中每個元素是”Audio“類型。
[ActivityModel mj_setupObjectClassInArray:^NSDictionary *{ return @{ @"audiolist":@"Audio" };}];另外返回的JSON中key可能會以"new"開頭,而我們定義模型時成員變量使用new開頭會報錯,這時需要將JSON中的key轉換成模型中的成員變量名,
[LeaderBoardData mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ return @{ @"newsList":@"newList" };}];reactiveCocoa
reactiveCocoa在這里的應用和網絡請求結合在了一起,載入主頁時,需要發出兩個http請求,等待這兩個請求都回返結果后再繼續下一步,reactiveCocoa可以非常簡單地完成這個動作,
MainFeatureViewModel.m
- (void)refreshDataSource{ @weakify(self); RACSignal *signalFocus = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { @strongify(self); [self requestFocusList:^{ [subscriber sendNext:nil]; }]; return nil; }]; RACSignal *signalRest = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { @strongify(self); [self requestRest:^{ [subscriber sendNext:nil]; }]; return nil; }]; [[RACSignal combineLatest:@[signalFocus,signalRest]] subscribeNext:^(id x) { @strongify(self); [(RACSubject *)self.updateContentSignal sendNext:nil]; }];}MVVM
下載鏈接: https://github.com/tom555cat/FenghuangFM.git歡迎star
新聞熱點
疑難解答