gpt4 book ai didi

objective-c - 如何判断 Safari 何时完成加载网页

转载 作者:行者123 更新时间:2023-11-28 20:35:18 25 4
gpt4 key购买 nike

我正在尝试弄清楚是否可以跟踪 Safari 何时完成加载页面请求。我调用 Safari 以使用此代码打开:

// Open Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.example.com/" description]]];

但是,由于我的应用进入后台,它可能是 suspended (and not able to execute code) .这甚至可以在 Xcode 4 中完成吗?

编辑

我之所以这样做是因为the UIWebView and Safari are not running at the same level我想在一些网站上做一些与性能相关的测试。

最佳答案

因此,如果您想了解我是如何为越狱的 iOS 做到这一点的(而不是非常无聊的“不可能”):我基本上是连接了 safari 以访问页面完成时调用的特定方法贷款。使用 MobileSubstrate(注入(inject)动态库时过滤 com.apple.mobilesafari):

#import <substrate.h>
#import <UIKit/UIKit.h>

/* Some globals */
static IMP _orig_1, _orig_2;
static id tabController;

id _mod_1(id __self, SEL __cmd, CGRect frame, id tabDocument);
void _mod_2(id __self, SEL __cmd, id doc, BOOL error);


/* The library constructor */
__attribute__((constructor))
static void init()
{
Class tabClass;

tabClass = objc_getClass("TabController");

MSHookMessageEx(tabClass, @selector(initWithFrame:tabDocument:),
(IMP)_mod_1, &_orig_1);
MSHookMessageEx(tabClass, @selector(tabDocument:didFinishLoadingWithError:),
(IMP)_mod_2, &_orig_2);
}


/* This hook merely captures the TabController of Safari. */
id _mod_1(id __self, SEL __cmd, CGRect frame, id tabDocument)
{
__self = _orig_1(__self, __cmd, frame, tabDocument);
tabController = __self;
return __self;
}

/* This is called when the page loading is done */
void _mod_2(id __self, SEL __cmd, id doc, BOOL error)
{
/* Make sure you always call the original method */
_orig_2(__self, __cmd, doc, error);

/* then do what you want */
}

关于objective-c - 如何判断 Safari 何时完成加载网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10760094/

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