简体   繁体   English

同步或异步获取用户ID(iOS)?

[英]Get the userID synchronously or asynchronously (iOS)?

I have a requirement.我有一个要求。 Some of the screens are not account based.有些屏幕不是基于帐户的。 So the users can view them without login.因此,用户无需登录即可查看它们。 But when they click the "favorite" button.但是当他们点击“收藏”按钮时。 The user will be asked to login in login page.将要求用户登录登录页面。 After login, if the user does login, the previous favorite action should be continued.登录后,如果用户确实登录了,应该继续之前的收藏动作。 And if the user did not login, the previous action should be stopped.如果用户没有登录,则应该停止之前的操作。

So I think this an asynchronously login case.所以我认为这是一个异步登录案例。 The usual synchronous way can not handle this.通常的同步方式无法处理这个问题。 So my idea is to pass in a login completion block.所以我的想法是传入一个登录完成块。 Like this:像这样:

typedef void (^LoginComplete)(NSString *userID);

- (void)getUserIDWithCompletion:(LoginComplete)loginComplete;

Am I right?我对吗? Or how do u guys usually handle this kind of case?或者你们通常如何处理这种情况?

Usually, all networking is done asynchronously from the developers perspective, aka, completion closures.通常,从开发人员的角度来看,所有网络都是异步完成的,也就是完成闭包。 This is however a synchronous operation for the user, since they are blocked from viewing the rest of the content until the operation continues.然而,这对用户来说是一个同步操作,因为在操作继续之前,他们无法查看内容的 rest。

Either way, your approach is good.无论哪种方式,您的方法都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM