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