gpt4 book ai didi

iphone - 获取 UIWebView URL 的查询

转载 作者:行者123 更新时间:2023-12-03 20:30:51 26 4
gpt4 key购买 nike

嘿,大家好,我正在尝试找到一种方法来专门从我的 UIWebView 当前已加载的 URL 中获取查询字符串。

例如:

www.google.com?page=235

我希望最终得到一个带有文本“page=235”的 NSString

或者更好的页面,标题为 NSData 键,ID 键为 235。

我基本上是在尝试将查询字符串组织成可用的数据。

在我的项目中,我有一个按钮:

[HTML appendString:@"<a href='didtap://goto?Page=56'>Post Comment</a>"];

我通过检查绝对URL来访问该按钮以查看按钮是否被触发。

有什么方法可以按照我想要的方式分析信息吗?

最佳答案

我创建了您想要的演示,这将进一步描述..

以下是viewcontroller.h文件代码

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
NSURL *Url;
}
@property(nonatomic,retain)IBOutlet UIWebView *webVctr;
@end

这可能有助于解决您的问题谢谢

以下是viewcontroller.m文件代码

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize webVctr = _webVctr;


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"%@",request);
Url = [request URL];
// if ([[UrlParts objectAtIndex:(1)] isEqualToString:@"NeverGonnaFindMe"]) {
// CONVERT TO STRING AN CLEAN
NSString *urlResources = [Url resourceSpecifier];
urlResources = [urlResources stringByReplacingOccurrencesOfString:@"?" withString:@"/"];

// SEPORATE OUT THE URL ON THE /
NSArray *urlResourcesArray = [urlResources componentsSeparatedByString:@"/"];
// THE LAST OBJECT IN THE ARRAY
NSString *urlParamaters = [urlResourcesArray objectAtIndex:([urlResourcesArray count]-1)];
// SEPORATE OUT THE URL ON THE &
NSArray *urlParamatersArray = [urlParamaters componentsSeparatedByString:@"&"];

if([urlParamatersArray count] == 1) {
NSString *keyValue = [urlParamatersArray objectAtIndex:(0)];
NSArray *keyValueArray = [keyValue componentsSeparatedByString:@"="];

if([[keyValueArray objectAtIndex:(0)] isEqualToString:@"page"]) {
NSLog(@"%@",[keyValueArray objectAtIndex:1]);
}

[self dismissModalViewControllerAnimated:YES];
return NO;
}
return YES;
}
// ACTIVITY INDICATOR
- (void)webViewDidStartLoad:(UIWebView *)webView{
/// [_activityIndicator startAnimating];
NSLog(@"Resting to server");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
// [_activityIndicator stopAnimating];
NSLog(@"Finish request server");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(@"Error");
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullAuthUrlString =[[NSString alloc] initWithFormat:@"www.google.com?page=235"];
NSURL *authUrl = [NSURL URLWithString:fullAuthUrlString];
NSURLRequest *myRequest = [[NSURLRequest alloc] initWithURL:authUrl];
[self.webVctr loadRequest:myRequest];
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

关于iphone - 获取 UIWebView URL 的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11499271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com