Broken HTTP basic authentication in web apps on iOS 7?

后端 未结 4 1269
日久生厌
日久生厌 2021-02-04 17:14

I\'m using basic authentication for a simple app but it stopped working in web app mode on iOS 7. It works in Safari, it worked on iOS 6 both in Safari and as a standalone web a

4条回答
  •  深忆病人
    2021-02-04 17:34

    This worked for me.

    + (void) setBasicAuth
    {
      NSURLCredentialStorage* store = 
        [NSURLCredentialStorage sharedCredentialStorage];
    
      NSURLCredential* creds = 
        [NSURLCredential credentialWithUser:@"user" 
                                   password:@"pass"
                                persistence:NSURLCredentialPersistenceForSession];
    
      NSURLProtectionSpace* protectionSpace = 
        [[NSURLProtectionSpace alloc] initWithHost:@"your-host" 
                                              port:80 
                                          protocol:@"http" 
                                             realm:@"Your Realm"
                              authenticationMethod:NSURLAuthenticationMethodDefault];
    
      [store setCredential:creds forProtectionSpace:protectionSpace];
    }
    

提交回复
热议问题