我在这里使用这个方法是一个注销方法,并且假设要清除我创建的会话:
NSURLCredential *credential = [NSURLCredential
credentialWithUser:user
password:password
persistence:NSURLCredentialPersistenceForSession];
问题是,信用证没有被清除......如果我在方法的末尾加上一个断点并运行我的代码就行了,但没有断点它不起作用,这里是方法:
- (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];
}
我从这个例子中得到了这段代码:
http://www.springenwerk.com/2008/11/i-am-currently-building-iphone.html
我做错了什么?
该方法中的代码也会发出警告:
/Users/jsuske/Documents/SSiPad(Device Only)ios7/SchedulingiPadApplication/ViewControllers/LHLoginController.m:523:105: Local declaration of 'userName' hides instance variable
为什么会这样?