ポリシー リスナーを実装するには、次のようにする必要があります。
WebPolicyDecisionListener.h:
// ...
@interface WebPolicyDecisionListener: NSObject {
// ...
}
// Implement PolicyDelegate
-(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener;
-(void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
newFrameName:(NSString *)frameName
decisionListener:(id <WebPolicyDecisionListener>)listener;
// ...
@end
WebPolicyDecisionListener.m
@implementation WebPolicyDecisionListener
// ...
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener
{
if (WebNavigationTypeLinkClicked == [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue])
{
// link was clicked do something with it...
}
[listener use]; // Say for webview to do it work...
}
-(void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
newFrameName:(NSString *)frameName
decisionListener:(id <WebPolicyDecisionListener>)listener
{
if (WebNavigationTypeLinkClicked == [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue])
{
// link was clicked and webview want to open it in new window do something with it...
}
[listener ignore]; // ignore webview default implementation...
}
// ...
@end
コードのどこかで次のようになります。
WebPolicyDecisionListener* listener = [[WebPolicyDecisionListener alloc] init];
// ...
[_WebCont setPolicyDelegate:listener];