1

我有为 iOS 开发的 phonegap 应用程序,我想在特定条件下设置 startPage,否则应用程序应该加载不同的另一个页面作为启动页面。

我是 Objective C 的新手,不知道 AppDelegate.m 中的这个方法

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//code
}

有没有可用的插件或代码来实现这一点?

4

3 回答 3

0

使用 javascript 并检查 DeviceReady 事件中的条件并更改页面

于 2013-07-18T10:18:10.940 回答
0

问题陈述:

我的应用程序有两个选项:

  1. 演示
  2. 顾客

默认页面显示以上两个选项,如果用户选择了客户,那么下次启动应用程序时应用程序应该自动跳过默认页面(即用户将被重定向到客户的主页)。

解决方案是:

假网址

  1. 当用户选择两个选项之一时,应用会点击假网址:

window.location.href="myfakeurl.html*演示*params"

附加到此网址的参数为:客户或演示(由**分隔)

  1. 在 MainViewController.m

添加以下处理 url 命中的方法:

-(BOOL) webView:(UIWebView*)WebView 应该StartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

 NSString *url = [[request URL] absoluteString];
 NSArray *myarray=[[NSArray alloc]init];

 if(url.length > 0)
 {
      NSLog(@"%@",url);
      if ([url hasPrefix:@"myfakeurl"])
      {

           myarray=[url componentsSeparatedByString:@"**"];
           NSString *params=[myarray objectAtIndex:1];

           NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www"];
           path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
           NSString *str = @"//";

           path = [NSString stringWithFormat:@"file:%@%@/homepage.html%@",str,path,params];
           NSURLRequest *newRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:path]] ;

           [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isCustomer"];
           [[NSUserDefaults standardUserDefaults] synchronize];
           [theWebView loadRequest:newRequest];


           return NO;

      }

 }    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; }
  1. 现在在 AppDelegate.m

检查 nsuserdefaults 中的 key 并适当设置启动页面,如下所示:

-(BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
//其他代码

//...

 self.viewController.startPage = [[NSUserDefaults standardUserDefaults] boolForKey:@"isCustomer"] ? @"homepage.html" :

@"default.html"; //......

return YES; }
于 2013-11-08T14:23:46.483 回答
-1

如果您仔细查看,它就在方法本身中didFinishLaunchingWithOptions

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{    
    NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
    if (url && [url isKindOfClass:[NSURL class]]) {
      self.invokeString = [url absoluteString];
      NSLog(@"TestAnother launchOptions = %@", url);
    }    

CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
self.window.autoresizesSubviews = YES;

CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];

self.viewController = [[MainViewController alloc] init];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index2.html";
self.viewController.view.frame = viewBounds;

.
.
.
.


    return YES;
}

您可以检查条件并设置 self.viewController.startPage = @"index2.html";

于 2013-07-18T10:30:21.333 回答