Ios 目标-c NSURL认证存储和删除不起作用
我这里有一个方法,它是一个注销方法,可以清除由以下人员创建的会话:Ios 目标-c NSURL认证存储和删除不起作用,ios,objective-c,Ios,Objective C,我这里有一个方法,它是一个注销方法,可以清除由以下人员创建的会话: NSURLCredential *credential = [NSURLCredential credentialWithUser:user password:password persistence:NSURLCrede
NSURLCredential *credential = [NSURLCredential
credentialWithUser:user
password:password
persistence:NSURLCredentialPersistenceForSession];
问题是没有清除creds…如果我在方法末尾放置断点并运行代码,它会工作,但如果没有断点,它就不工作,方法如下:
- (void)LogoutButtonPressed
{
//@TODO: Fix Logout
/*NSURLCredentialStorage *credentialStorage = [NSURLCredentialStorage sharedCredentialStorage];
NSDictionary *credentialsDicationary = [credentialStorage allCredentials];
for (NSURLProtectionSpace *space in [credentialsDicationary allKeys]) {
NSDictionary *spaceDictionary = [credentialsDicationary objectForKey:space];
for (id userName in [spaceDictionary allKeys]) {
NSURLCredential *credential = [spaceDictionary objectForKey:userName];
[credentialStorage removeCredential:credential forProtectionSpace:space];
}
}*/
// reset the credentials cache...
NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
if ([credentialsDict count] > 0) {
// the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName => NSURLCredential
NSEnumerator *protectionSpaceEnumerator = [credentialsDict keyEnumerator];
id urlProtectionSpace;
// iterate over all NSURLProtectionSpaces
while (urlProtectionSpace = [protectionSpaceEnumerator nextObject]) {
NSEnumerator *userNameEnumerator = [[credentialsDict objectForKey:urlProtectionSpace] keyEnumerator];
id userName;
// iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials
while (userName = [userNameEnumerator nextObject]) {
NSURLCredential *cred = [[credentialsDict objectForKey:urlProtectionSpace] objectForKey:userName];
NSLog(@"cred to be removed: %@", cred);
[[NSURLCredentialStorage sharedCredentialStorage] removeCredential:cred forProtectionSpace:urlProtectionSpace];
}
}
}
[loginMenuView setFrame:CGRectMake(loginMenuView.frame.origin.x, loginMenuView.frame.origin.y, 410, 184)];
[logingMetalBg setFrame:CGRectMake(loginMenuView.bounds.origin.x, loginMenuView.bounds.origin.y, loginMenuView.bounds.size.width, loginMenuView.bounds.size.height)];
/*LHAppDelegate *appDelegate = (LHAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.loginSession setString:@""];
[appDelegate.nameOfUser setString:@""];*/
[logoutButton removeFromSuperview];
logoutButton = nil;
//[[logoutPopup getPopOver ]dismissPopoverAnimated:NO];
//logoutPopup = nil;
[settingsPage hide];
[self.menu removeFromSuperview];
self.menu = nil;
menuItems = nil;
[self MenuOrLogin];
}
我从这个例子中得到了以下代码:
我做错了什么
方法中的代码也会出现警告:
/Users/jsuske/Documents/SSiPad(Device Only)ios7/SchedulingiPadApplication/ViewControllers/LHLoginController.m:523:105: Local declaration of 'userName' hides instance variable
为什么会发生这种情况?您会收到警告,因为您使用了一个本地属性
userName
,并且已经实现了一个同名的全局属性。重命名它们可以消除警告。