2009-07-06 8 views
0

私のウェブサイトをiPhoneネイティブアプリケーションに変換する予定です。私はこれを達成する方法のポイントに立ち往生しています。ウェブサイトをiPhoneネイティブアプリケーションとして作成するにはどうすればよいですか?

最初は、最初の画面、つまり自分のアプリケーションのログイン画面を開発しました。私のサーバーはJavaで構築されています。私は、ログイン資格情報をサーバーに送信することができ、サーバー上の要求を見ることができます。しかし、私が送ったリクエストに対するサーバーからの応答を受け取ることができません。

私のコードの一部である:

NSString *post = @"username="; 

    post = [post stringByAppendingString:username]; 
    post = [post stringByAppendingString:@"&password="]; 
    post = [post stringByAppendingString:password]; 

    NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:[NSURL URLWithString:@"http://mysite.com/login.action?"]]; 
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    // [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPBody:postData]; 

    NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    if (conn) 
    { 
     receivedData = [[NSMutableData data] retain]; 
     NSLog(@"In \"LOGIN()\" : receivedData = %@",receivedData); 
    } 


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [receivedData setLength:0]; 

    NSLog(@"In \"didReceiveResponse()\" : receivedData = %@",receivedData); 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [receivedData appendData:data]; 
    NSString *ReturnStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    NSLog(@"In \"didReceiveData()\" : receivedData = %@",receivedData); 
    NSLog(@"Return String : %@", ReturnStr); 

} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]); 


    NSString *urlData; 
    if (nil != receivedData) { 
     urlData = [[[NSString alloc] initWithData:receivedData 
             encoding:NSUTF8StringEncoding] autorelease]; 
    } 
    NSLog(@"In \"connectionDidFinishLoading()\" : urlData = %@",urlData); 

    [receivedData release]; 
} 


- (void)connection:(NSURLConnection *)connection 
    didFailWithError:(NSError *)error 
{ 

    [connection release]; 

    [receivedData release]; 


    NSLog(@"Connection failed! Error - %@ %@", 
      [error localizedDescription], 
      [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); 
} 
  1. どのように私はログインアプリケーションを開発していますか?
  2. サーバーにリクエストを正常に送信していますが、サーバーからの応答を取得できません。どうすればこの問題を克服できますか?

答えて

1

ウェブ開発の経験があれば、NimbleKit for iPhoneをご覧になることをお勧めします。 HTMLとJavaScriptを使ってネイティブアプリケーション全体を開発できるシンプルなXCodeプラグインです。

関連する問題