0

我想知道是否有人可以帮助解析 XCODE 中受保护的 XML 文件。

这是我得到的,但我不知道如何混淆这些东西,因为我在 XCODE 中还很新。

与认证的连接

    -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:    (NSURLAuthenticationChallenge *)challenge
{   
if ([challenge previousFailureCount] == 0) {
    NSURLCredential *newCredential;
    newCredential=[NSURLCredential credentialWithUser:@"myusername"
                                             password:@"mypassword"
                                          persistence:NSURLCredentialPersistenceNone];
    [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
} else {
    [[challenge sender] cancelAuthenticationChallenge:challenge];
    NSLog(@"Bad Username Or Password");

    UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Authentication Error" message:@"Unable to connect to the server, Please Contact The WebMaster." delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [aler show];
    [aler release]; 
}
    }

解析代码

    -(void)doParse
{
[SongArray removeAllObjects];
//NEED TO GET XML DOCUMENT INTO NSData OBJECT!!!
NSURL *theURL = [[NSURL alloc] initWithString:@"myurl"];
// create and init NSXMLParser object



NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
// create and init our delegate
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//set delegate
[nsXmlParser setDelegate:parser];
//parsing...
BOOL success = [nsXmlParser parse];
// test the result
if (success) {
    NSLog(@"success");
    SongArray = [parser getPeople];
    [self.SongDescription reloadData];

} else {

    UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Server Error" message:@"Unable To Read The Song Information, You May Keep Listening To The Radio Without Song Information" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [aler show];
    [aler release];

    NSLog(@"fail");
}

    }
4

0 回答 0