【发布时间】:2017-12-30 01:20:35
【问题描述】:
我一直在使用 Restkit 连接到我的 API 服务器,它运行良好。现在我的情况是我在didFinishLaunchingWithOptions 的appdelegate.m 中添加了一个检查器。它检查 coredata 中是否已经存在 adminID。如果存储了 adminID,当应用程序重新启动时,它会将 rootviewcontroller 设置为 uinavigation 控制器。但是调用uiviewcontroller时,不会调用RestkitenqueueObjectRequestOperation。
这是我的代码:
在 appdelegate.m 中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//adminID is fetch from custom Entity in core data
if(adminID==0){
AllKommunScreenViewController *adminController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AllKommunScreenID"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:adminController];
self.window.rootViewController = navController;
}
return YES;
}
这是我在导航控制器的 Rootview 中的代码:
-(void)fetchData{
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Auth class]];
[responseMapping addAttributeMappingsFromArray:@[@"status", @"sucess", @"data"]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *userProfileDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:statusCodes];
NSString *apiPath = [NSString stringWithFormat:@"%@%@", baseURL,@"/api/kommun/all/stats/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiPath]];
request setValue:_sharedManager.userAccessToken forHTTPHeaderField:@"X-ACCESS-TOKEN"];
RKObjectRequestOperation *operation =[[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[userProfileDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {} failure:^(RKObjectRequestOperation *operation, NSError *error) {}];
[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation];
}
我在 viewWillAppear 中调用了fetchData。
然后我在函数中添加一个断点,然后它就到了那里,问题是restkit没有调用enqueueObjectRequestOperation。
请帮忙!!!
顺便说一句,我制作了一个自定义核心数据实体来存储 adminID
【问题讨论】:
标签: ios objective-c restkit