我正在尝试实现一个后台获取方法来获取新数据,但它给了我一个 NSMutable Dictionary 错误。这是我的代码
在我的 appDelegate 下 performFetchWithCompletionHandler 我有:
UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
id topViewController = navigationController.topViewController;
if ([topViewController isKindOfClass:[viewController class]])
{
[(viewController*)topViewController autologin];
}
else
{
completionHandler(UIBackgroundFetchResultNewData);
}
这在我的视图控制器中调用自动登录
- (void) autologin
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* username = [defaults valueForKey:@"username"];
NSString* password = [defaults valueForKey:@"password"];
[self login:username password:password];
}
然后调用登录
- (void)login:(NSString*)username password:(NSString*) password
{
NSDictionary *login = [[NSDictionary alloc] initWithObjectsAndKeys:username, @"username", password, @"password", NO, @"showNotification", nil];
NSOperationQueue* backgroundQueue = [NSOperationQueue new];
ch = [[backgroundProcess alloc] init];
NSInvocationOperation* operation = [[NSInvocationOperation alloc] initWithTarget:ch selector:@selector(runEvents:) object:login];
[backgroundQueue addOperation:operation];
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(checkStatus) object:nil];
[backgroundQueue addOperation:operation];
}
如果我的应用程序在前台运行并且我调用登录函数,那么一切正常,但是一旦它命中就使用 performFetchWithCompletionHandler
NSDictionary *login = [[NSDictionary alloc] initWithObjectsAndKeys:username, @"username", password, @"password", NO, @"showNotification", nil];
我得到 EXC_BAD_ACCESS。任何帮助,将不胜感激!