如何通过延迟从方法返回值?

时间:2016-03-03 06:58:59

标签: ios objective-c

我有一个框架和一个项目。我的框架负责Web服务。

从Project用户插入用户名和密码。然后它通过在框架内调用sendLogin方法传递这些参数。

在内部框架中,检查并验证用户名和密码需要一段时间。如果用户名和密码正确,它将从服务器获得一个令牌号。

直到这里一切正常。但我想知道如何将此令牌发送回主程序?

我尝试了完成方法,但我失败了。这是定义:

项目:

- (IBAction)bankLoginPressed:(id)sender
{
    [registerUser sendLogin:^(NSInteger *accessCode){

        NSLog(@"access code ==  %tu ",accessCode);

    }];
}

内部框架

typedef void (^HttpCompletionBlock) (NSInteger *);

-(void) sendLogin :(HttpCompletionBlock)completionHandler
{
    NSString *string = @"https://myserver/customer_authentication";
    NSDictionary *parameters = @{@"member_id": @"1234", @"access_code": @"password", @"device_id":@"874627864"};

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:string parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {

        NSLog(@"JSON: %@", responseObject);
        if (responseObject[@"secret_token"])
        {

            NSLog(@"Secret is=    %@",responseObject[@"secret_token"]);
            //Here I needd to send back token number????

        }
    }
          failure:^(NSURLSessionTask *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
}

1 个答案:

答案 0 :(得分:2)

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5">

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:orientation="horizontal">

 <EditText
  android:id="@+id/edittext"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/enter_text" android:inputType="text" />

 </LinearLayout>

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:orientation="horizontal"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal"/>

    </LinearLayout>
相关问题