我正在製作一個iOS應用程序,允許2個用戶互相交互。當第一個用戶使用UIWebView導航到他的應用程序上的URL時,我會將此URL發送給第二個用戶。第二個用戶收到此鏈接並使用UIWebView加載它。我如何檢測UIWebview在iOS中加載需要身份驗證的url
一切都很好,直到一個人進入私人區域。例如,第一位用戶訪問www.google.com並登錄他的Gmail帳戶時。現在我捕獲這個鏈接併發送給第二個用戶,他嘗試加載它,但是這個失敗了,因爲它是第一個用戶的私人區域。
第二位用戶的UIWebView如何知道接收到的url是在私人區域還是必須通過身份驗證才能訪問?
這裏一些例證代碼:
在第一用戶,當導航像www.google.com的網址。我稱這個功能爲
- (void)loadRequestUrl:(NSString *)url {
NSLog(@"load request");
//Load request
self.websiteUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:websiteUrl]];
[wbWebview loadRequest:request];
//Send url to partner
//I'm using GCDAsyncSocket to send this url string to our server
//And server will send it to my current partner
//Just example code for sending
[asyncSocket send:url];
}
//在第二位用戶。我從GCDAsyncSocket的代理收到了url字符串。在此委託我調用這個函數
- (void)receiveUrl:(NSString *)url {
//Just Load request
self.websiteUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:websiteUrl]];
[wbWebview loadRequest:request];
}
第二用戶接收之後URL的例子,但不能打開。我永遠不能捕捉到錯誤的任何代表
重要性:我並不需要強制第二個用戶打開它,我只是想捕獲事件告訴第二個用戶是第一個用戶進入私人區
我們展示你的代碼。 – Neeku