0

セキュアコードを追加する Web サービス URL があります。たとえばabcdと言うために正しいセキュアコードを入力すると、アプリケーションがロードされます。間違ったセキュア コードを入力したときに、「間違ったセキュア コード」としてアラートを表示する必要があります。私のコードはここにあります:

- (void) alertStatus:(NSString *)msg :(NSString *)Title:(int)tag
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Title

                                                    message:msg
                                                   delegate:self
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles:nil, nil];
    if(tag) 
        alertView.tag = tag;
    [alertView show];
}


-(IBAction)loginClicked:(id)sender {

    @try {

        if([[txtsecurecode text] isEqualToString:@""]  ) {
            [self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
        } else {
            NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];

            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidAccess?accesscode=%@&type=1",txtsecurecode.text]];

            NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];

responseData は、Web サービス url から応答を取得している参照です。応答を取得する以下では、注意を払う必要があります。

間違った安全なコードを入力したときにアラートを表示するこの場合、アラートを維持するにはどうすればよいですか?

4

6 に答える 6

0
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding])

    if ([responseString isEqualToString:@"Success"]) {
       NSLog(@"Success");
    }
    else {

       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Title 
                                               message:msg
                                               delegate:self
                                      cancelButtonTitle:@"Ok"
                                      otherButtonTitles:nil, nil];
       [alertView show];
    }

    [responseData release];
    responseData = nil;

    [connection release];
    connection = nil;
}
于 2013-03-19T06:20:26.783 に答える
0

あなたがしたいことはあなたが応答を得るところで行われます。

応答には、成功または失敗を通知する変数があります。

その値を確認してください。

  • 値が成功を示している場合。それが示している場合は続行します。
  • 失敗すると、「認証はアラートとして失敗しました。
于 2013-03-19T06:03:00.057 に答える
0

あなたはそれがあなたの望む答えを与えているかどうかにかかわらず、あなたの応答をチェックしなければなりません。

-適切な答えが得られない場合は、alertViewをここに表示できます。それ以外の場合は、さらにロジックを続行できます。

于 2013-03-19T06:13:33.930 に答える
0

実際に特定のメソッドに名前を付けているのに、なぜタグが必要なのかわかりません。たぶん、コードは次のように単純にすることができますか?

- (void) alertStatus:(NSString *)msg :(NSString *)Title {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Title
                                                message:msg
                                               delegate:self
                                      cancelButtonTitle:@"Ok"
                                      otherButtonTitles:nil, nil];
[alertView show];
return;
}
于 2013-03-19T06:06:58.707 に答える
0

このコードを使用してみてください...

-(IBAction)loginClicked:(id)sender {

    @try {

        if([[txtsecurecode text] isEqualToString:@""]  ) {
            [self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
        } else {
            NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];

            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidAccess?accesscode=%@&type=1",txtsecurecode.text]];


            /*UPDATED*/
            NSString *responseData = [[NSString alloc]initWithContentsOfURL:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding error:nil];


            if([responseData isEqualToString:@""])
            {
                [self alertStatus:@"Please enter valid Access code" :@"Login Failed!":0];
            }
            else
            {
                //Your code for handling the response data
            }
        }
    }
}
于 2013-03-19T06:44:07.567 に答える
0

有効なコードと無効なコードの Web サービス データからの応答を確認する必要があります。

この方法で取得します::

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    value = [[NSString alloc] initWithBytes: [webdata mutableBytes] length:[webdata length] encoding:NSUTF8StringEncoding];
    NSLog(@"==>%@", value);
    
    if ([value isEqualToString:@"Valid"]) {
       NSLog(@"Valid");
    }
    else {
       NSLog(@"Invlid");

       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Title 
                                               message:msg
                                               delegate:self
                                      cancelButtonTitle:@"Ok"
                                      otherButtonTitles:nil, nil];
       [alertView show];
    }
    
    [webData release];
    webData = nil;
    
    [connection release];
    connection = nil;
}

「値」に基づいて、有効なコードと無効なコードを確認できます。

于 2013-03-19T06:11:31.727 に答える