我一直在使用Restkit連接到我的API服務器,並且它完美地工作。現在我的情況是我在我的appdelegate.m
的didFinishLaunchingWithOptions
中添加了一個檢查器。它會檢查coredata中是否已經存在adminID。如果存儲了adminID,當應用程序重新啓動時,它會將rootviewcontroller設置爲uinavigation控制器。但是當調用uiviewcontroller時,不會調用Restkit enqueueObjectRequestOperation
。Restkit-enqueueObjectRequestOperation在appdelegate中添加rootviewcontroller之後不會被調用
這裏是我的代碼:
在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