iOS load 2 web views depending on user first launch

冷暖自知 提交于 2020-01-17 09:21:59

问题


hi apologies for my spelling and English in advance

what I want is to build a Webview application for iOS in objc or swift doesn't matter, the app works with 2 url links in the Webview to do the following.

Q1. url1 opens only on app first launch then inside url 1 there will be a register info form where the user should insert he's information after this info Is completed the user then push button "continue" inside Webview to continue to the website home page inside the webiview.

Q2. if app closes and reopens again then the app should register or remember that url 1 was opened and the "continue" button inside the Webview, was pushed there for this app then needs to open url2 and always open this url. I have builded this application in android but cannot get this in iOS. please help thank you in advance nd sorry for the way of this explanation im new in iOS and need to finish this app with in 3days. thanks for your attention.


回答1:


Firstly you need to create a redirect url for your login api which will be opened if successful registered. Next set delegate of your webview. Use this delegate method to identify redirect url.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

Then set bool in NSUserDefaults like

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"IsUserLoggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];

Synchronize is method to persist value immediately. NSUserDefaults is persistent way to store flags. It persist its value until app is not deleted from device. You can update its value any time or remove value for any key with

[[NSUserDefaults standardUserDefaults] removeObjectForKey: @"IsUserLoggedIn"];

Then on app launch get the value for key "IsUserLoggedIn" in bool and load url accordingly

BOOL isloggedIn = [[NSUserDefaults standardUserDefaults] boolForKey: @"IsUserLoggedIn"];

Note: If you want to make your app live on App Store. Then if your app will contain only a view with webview. Then apple will not approve it. Instead you need to add some native functionality. For eg. About Us, Contact Us page and Social Sharing.



来源:https://stackoverflow.com/questions/44064405/ios-load-2-web-views-depending-on-user-first-launch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!