너무 늦기는하지만 나중에 도움이 될 것입니다. 아래는 우리가 암호를 가져 응용 프로그램을 실행하면 암호
NSURLCredential *credential;
NSDictionary *credentials;
credentials = [[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[self createProtectionSpaceForBasicAuthentication]];
credential = [credentials.objectEnumerator nextObject];
NSLog(@"Username: %@ and password %@", credential.user, credential.password);
를 가져 오는에 대한 암호
- (IBAction)saveButtonClicked:(id)sender {
[self createCredentialForUsername:@"User_Name" Password:@"Your_Pass"];
}
저장을위한
#pragma -mark Password save in Keychain
-(NSURLProtectionSpace *)createProtectionSpaceForBasicAuthentication{
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost:@"http://yourURLHere"
port:1804 //add Your port here
protocol:@"http" //can be pass as nil
realm:nil
authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
return protectionSpace;
}
-(void)createCredentialForUsername:(NSString *)username Password:(NSString *)password{
NSURLCredential *credentialObject;
credentialObject = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent];
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:credentialObject forProtectionSpace:[self createProtectionSpaceForBasicAuthentication]];
}
맥
의 키 체인에 암호를 저장 한 것입니다, 우리는 키 체인 접근을위한 사용자 행동 프롬프트를 얻을 것입니다.
인터넷 암호가 제네릭 암호 시스템보다 설정에 약간 더 적합하다고 생각했지만 작동 할 수 있습니다. SSKeychain이 식별자로 사용하는 "서비스"에 URL을 인코딩 할 수있을 것 같습니다. 내 목적을 위해 더 좋은 점이 없다면 적어도 인터넷 암호를 사용하여 시스템을 구성하려는 경우 출발점입니다. – Noah