简体   繁体   English

应用启动屏幕和身份验证

[英]App launch screen and authentication

I have an app that is authenticating the user using a remote API. 我有一个使用远程API验证用户身份的应用程序。

Is it possible to use the launch screen to call the API and delay the launch of the initial controller? 是否可以使用启动屏幕来调用API并延迟启动初始控制器? I haven't figured that one out. 我还没有想到。

Thanks 谢谢

Launch screen (aka Default.png, or -568h, etc.) will automatically remove itself once app is loaded. 加载应用后,启动屏幕(aka Default.png或-568h等)将自动删除。 But there is a trick. 但是有一个窍门。 If you want to implement such functionality you can add UIImageView (with corresponding Default.png, or -568h, etc) as a subview above your root vc. 如果要实现此类功能,则可以在根vc上方添加UIImageView(具有相应的Default.png或-568h等)作为子视图。 And then remove it after auth. 然后在身份验证后将其删除。

So the user will still see the launch screen while your app is authenticating. 因此,在您的应用进行身份验证时,用户仍将看到启动屏幕。

In .h .h

UIImageView *launchImageView;

In .m .m

Under viewDiDLoad: viewDiDLoad:

launchImageView = [[UIImageView alloc] initWithFrame:[self bounds]];
launchImageView.image = [UIImage imageNamed:YOUR_IMAGE];
[self.view addSubView:launchImageView];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; //Network Activity Indicator if you want to show
//YOUR API GOES HERE

When you get the data from your API, then in the main thread , remove that launchImageView 从API获取数据后,请在主线程中删除该launchImageView

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[launchImageView removeFromSuperView];

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

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