-1

我已经构建了一个 iPhone 应用程序(不是 iPad),并且我正在 Web 视图控制器中运行一个网页。我的问题是 PHP 文件如何检测到它是从这个应用程序的 UIWebView 控制器而不是 Safari 中运行的。如果在这个应用程序中运行而不是 safari 移动网络浏览器,我希望 PHP 页面做出不同的反应(即摆脱 html 菜单)。这可能吗?

网络视图控制器

#import "AccountViewController.h"

@interface AccountViewController ()

@end

@implementation AccountViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidLoad];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"account" ofType:@"html"]isDirectory:NO];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_AccountWebView loadRequest:requestObj];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [sharedHTTPCookieStorage cookiesForURL:[NSURL URLWithString:@"http://www.uniitee.com"]];
    NSEnumerator *enumerator = [cookies objectEnumerator];
    NSHTTPCookie *cookie;
    while (cookie = [enumerator nextObject]) {
        NSLog(@"COOKIE{name: %@, value: %@}", [cookie name], [cookie value]);
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

PHP文件

<?php require_once('Connections/Uniitee.php'); 

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

if ($iphone || $android || $palmpre || $ipod || $berry == true) 
{ 
   header('Location: login-m.php');
}

?>
4

1 回答 1

1

您可以在应用程序中加载不同的 URL 参数,例如?appview=true,并在 PHP 中使用if($_GET['appview']).

然后,您可以设置一个应用程序视图为 true 的会话,以便在整个用户会话中使用

于 2013-05-03T08:05:38.147 回答