[英]Objective-C with JSON
第一個文件 SSDataProvider.m:
- (void)getGrades: callback:(SARequestCallback)callback {
[self personRequest:[NSString stringWithFormat:@"grades/"] callback:callback];
}
第二個文件 SSDataProvider.h:
- (void)getGrades: callback:(SARequestCallback)callback;
第三個文件:
if(appDelegate.user.community){
[[SSDataProvider instance] getGrades: callback:^(SARequestResult *result) {
[self stopSync];
if(result.status == SARequestStatusOK){
NSLog(@"Sync successful");
[self loadWithData:result.data];
if (deltaTime == 0) {
[self writeDict:result.data file:@"GradesCache-0"];
}
[self writeDict:result.data file:[NSString stringWithFormat:@"GradesCache-%@", time]];
}else if(result.error.code > 900){
// Show login dialog, but only if the error is a Scholica error, not a network error
NSLog(@"Scholica error, present login view: %@", result.error.errorDescription);
[self login:YES];
}else{
// Network error, so try again in a couple of seconds
NSLog(@"Network error, will try again soon.");
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(synchronize) userInfo:nil repeats:NO];
}
}];
}else{
syncing = NO;
[appDelegate getUser];
}
我希望使用對 /grades 的 API 調用獲取成績但這不起作用?
您的SSDataProvider
類中似乎存在語法錯誤。
你要:
SSDataProvider.m:
- (void)getGrades:(SARequestCallback)callback {
[self personRequest:[NSString stringWithFormat:@"grades/"] callback:callback];
}
SSDataProvider.h:
- (void)getGrades:(SARequestCallback)callback;
然后你可以這樣稱呼它:
[[SSDataProvider instance] getGrades:^(SARequestResult *result) {
// your block implementation
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.