IOS アプリの開発には Cordova 2.1.0 を使用します。MainViewController.m ファイルに shouldStartLoadWithRequest 関数として次のものがあります。
- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"shouldStartLoadWithRequest function");
// Intercept custom location change, URL begins with "js-call:"
if ([[[request URL] absoluteString] hasPrefix:@"js-call:"]) {
// Call the given selector
[self performSelector:NSSelectorFromString(@"resetBadgeCount")];
// Cancel the location change
return NO;
}
// Accept this location change
return YES;
}
問題は、私の index.html には次のようなものがあります:- window.location = "js-call:resetBadgeCount";
しかし、resetBadgeCount は AppDelegate.m ファイルに存在する関数であり、 shouldStartLoadWithRequest 関数が呼び出されるたびに、次のエラーが発生します。
-[MainViewController resetBadgeCount]: unrecognized selector sent to instance 0x199db0
では、エラーが抑制され、resetBadgeCount 関数が正常に呼び出されるように、コードをどのように変更すればよいでしょうか。