我有以下設計模式查詢問題。我有一個PHP的Web服務,我想從中執行,登錄授權和SQL操作,一些使用NSDictionary響應,一些使用BOOL響應。iOS網絡API設計模式想法?
我有設計模式的搜索和打擊這樣的:Best architectural approaches for building iOS networking applications (REST clients)
現在雖然這個職位是非常有趣的,我不認爲我需要什麼那麼複雜。我已經開始與一個單獨的對象爲assetDBConnection(這是在下面的代碼self.delegate],但我不知道這是否是最好的主意。
我能想到有我assetDBConnection抽象的唯一途徑從我APIWebRetrieve數據檢索走就是拉出來,從響應比較字符串。這意味着在PHP服務水平分爲不同的類型,比如:type =「登錄」分組的響應,等等等等。
-(void)APIWebRetrieveFinished:(APIWebRetrieve *)api
{
NSLog(@"api:%@",[api description]);
NSLog(@"%@",api.dataString);
NSError *error;
if (api.dataString) {
NSDictionary *results=[NSJSONSerialization JSONObjectWithData:[api.dataString dataUsingEncoding:NSStringEncodingConversionAllowLossy]
options:NSJSONReadingMutableContainers
error:&error];
if ([[results objectForKey:@"type"] isEqualToString:@"logon"]){
if ([results objectForKey:@"response"]){
[self.delegate loginOK];
}else{
[self.delegate loginFail];
}
}
}
}
任何幫助讚賞。
更新: 好吧,這一定很沉悶。沒有任何反應。我已經開始在服務中添加另一個層。我很喜歡這樣的事實,我現在有這樣的代碼彈出:
#import "AssetDBConnection.h"
#import "AssetDBServiceLogon.h"
@implementation AssetDBConnection
-(BOOL)loginWithUsername:(NSString*)user andPassword:(NSString*)password
{
[AssetDBService logonWithUsername:user password:password andDelegate:self];
}
我只是希望這是朝着正確的方向!
** bold **我去的是一個APIWebRetrieve類,它執行Web調用並返回一個JSON對象給一個(微 –