简体   繁体   中英

Objective-C with JSON

1st file SSDataProvider.m:

- (void)getGrades: callback:(SARequestCallback)callback {
    [self personRequest:[NSString stringWithFormat:@"grades/"] callback:callback];
}

2th file SSDataProvider.h:

- (void)getGrades: callback:(SARequestCallback)callback;

3th file:

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];
}

I want grades to be fetched using an API call to /grades But this is not working?

You seem to have a syntax error in your SSDataProvider class.

You want:

SSDataProvider.m:

- (void)getGrades:(SARequestCallback)callback {
    [self personRequest:[NSString stringWithFormat:@"grades/"] callback:callback];
}

SSDataProvider.h:

- (void)getGrades:(SARequestCallback)callback;

And then you can call it like:

[[SSDataProvider instance] getGrades:^(SARequestResult *result) {
    // your block implementation
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM