在 iOS 中使用 PhoneGap Cleaver 覆盖方法

     2023-03-15     250

关键词:

【中文标题】在 iOS 中使用 PhoneGap Cleaver 覆盖方法【英文标题】:Using PhoneGap Cleaver in iOS to override method 【发布时间】:2013-10-07 06:27:12 【问题描述】:

我正在使用 PhoneGap 2.3 - Cleaver for iOS。

如何覆盖 shouldStartLoadWithRequest、webViewDidStartLoad、webViewDidFinishLoad 函数?

如果我在viewDidLoad中添加“viewController.webView.delegate = self”,则可以调用上面的函数,但不能调用PhoneGap API。

谢谢。

MyViewController.m:

- (void)viewDidLoad

    [super viewDidLoad];
    CDVViewController* viewController = [CDVViewController new];
    viewController.view.frame = self.view.bounds;
    //viewController.webView.delegate = self;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:landingURL]];
    [viewController.webView loadRequest:request];
    [self.view addSubview:viewController.view];
    [self addChildViewController:viewController];

MyViewController.h:

@interface MyViewController : UIViewController <UIWebViewDelegate>
@end

【问题讨论】:

【参考方案1】:

您不应覆盖 shouldStartLoadWithRequest,因为它们在其中管理调用本机函数的 javascript url。

或者至少将他们的代码从 CDVViewController 复制到您的视图控制器中并添加您需要的东西。

phonegap 2.9.1 中的示例

    - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

    NSURL* url = [request URL];

    /*
     * Execute any commands queued with cordova.exec() on the JS side.
     * The part of the URL after gap:// is irrelevant.
     */
    if ([[url scheme] isEqualToString:@"gap"]) 
        [_commandQueue fetchCommandsFromJs];
        return NO;
    

    /*
     * If a URL is being loaded that's a file/http/https URL, just load it internally
     */
    else if ([url isFileURL]) 
        return YES;
    

    /*
     *    If we loaded the HTML from a string, we let the app handle it
     */
    else if (self.loadFromString == YES) 
        self.loadFromString = NO;
        return YES;
    

    /*
     * all tel: scheme urls we let the UIWebview handle it using the default behavior
     */
    else if ([[url scheme] isEqualToString:@"tel"]) 
        return YES;
    

    /*
     * all about: scheme urls are not handled
     */
    else if ([[url scheme] isEqualToString:@"about"]) 
        return NO;
    

    /*
     * all data: scheme urls are handled
     */
    else if ([[url scheme] isEqualToString:@"data"]) 
        return YES;
    

    /*
     * Handle all other types of urls (tel:, sms:), and requests to load a url in the main webview.
     */
    else 
        if ([self.whitelist schemeIsAllowed:[url scheme]]) 
            return [self.whitelist URLIsAllowed:url];
         else 
            if ([[UIApplication sharedApplication] canOpenURL:url]) 
                [[UIApplication sharedApplication] openURL:url];
             else  // handle any custom schemes to plugins
                [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
            
        

        return NO;
    

    return YES;

if ([[url scheme] isEqualToString:@"gap"]) 管理 phonegap 呼叫

顺便说一句,您不应该使用 phonegap 2.3,您至少需要 2.5 才能通过 5 月添加的苹果商店指南,2.5 之前的版本使用 UDID,并且被苹果禁止

【讨论】:

如何在 iOS 中使用自定义 phonegap 3.3 插件

】如何在iOS中使用自定义phonegap3.3插件【英文标题】:Howtousecustomphonegap3.3plugininiOS【发布时间】:2014-01-2705:33:00【问题描述】:我已经在phonegap2.9中使用了phonegap插件(SQLitePlugin),但现在我想将我的项目转换为phonegap3.3,我已经按... 查看详情

在 iOS 中使用 PhoneGap Cleaver 覆盖方法

】在iOS中使用PhoneGapCleaver覆盖方法【英文标题】:UsingPhoneGapCleaveriniOStooverridemethod【发布时间】:2013-10-0706:27:12【问题描述】:我正在使用PhoneGap2.3-CleaverforiOS。如何覆盖shouldStartLoadWithRequest、webViewDidStartLoad、webViewDidFinishLoad函数... 查看详情

无法使用xcode phonegap在ios中隐藏状态栏

】无法使用xcodephonegap在ios中隐藏状态栏【英文标题】:canthidestatusbariniosusingxcodephonegap【发布时间】:2013-03-0911:02:40【问题描述】:我正在尝试删除我的xcodeiOS项目中的状态栏。phonegap2.5版。我试过以下。1)通过在config.xml中添加以... 查看详情

如何在 iOS 中使用 Admob Phonegap 插件

】如何在iOS中使用AdmobPhonegap插件【英文标题】:HowtouseAdmobPhonegappluginwithiOS【发布时间】:2012-05-2018:23:29【问题描述】:我正在使用thisAdmobpluginforPhonegap在iOS上运行,如下所示:window.plugins.AdMob.createBanner("siteId":"my-site-id");window.plug... 查看详情

使用 AngularJS 在 iOS 的 PhoneGap 3.3 中登录 XCODE

】使用AngularJS在iOS的PhoneGap3.3中登录XCODE【英文标题】:LoggingtoXCODEinPhoneGap3.3foriOSwithAngularJS【发布时间】:2014-01-2500:32:29【问题描述】:已经有几个关于在phonegap项目中登录XCode的问题(例如console.lognotworkinginaniOSPhoneGap3.0app),但... 查看详情

在 PhoneGap 中使用 JavaScript 创建和使用 iOS settings.bundle 值

】在PhoneGap中使用JavaScript创建和使用iOSsettings.bundle值【英文标题】:CreatingandusingiOSsettings.bundlevalueswithJavaScriptinPhoneGap【发布时间】:2012-03-1613:49:48【问题描述】:是否可以在iPhone设置应用程序中使用PhoneGap(v1.4.1)创建一个部分?... 查看详情

在 iOS 中使用 Phonegap Canvas 自定义字体

】在iOS中使用PhonegapCanvas自定义字体【英文标题】:CustomfontsiniOSwithPhonegapCanvas【发布时间】:2013-03-2202:38:46【问题描述】:我正在尝试在iOS下的Phonegap中制作自定义字体。我遵循了几个教程并阅读了有关StackOverflow的所有相关问题... 查看详情

使用 phonegap 在 IOS 的图库中查看使用 FileWriter 写入文件系统的图像文件

】使用phonegap在IOS的图库中查看使用FileWriter写入文件系统的图像文件【英文标题】:ViewimagefilewrittentofilesystemusingFileWriteringalleryinIOSusingphonegap【发布时间】:2014-02-0622:33:27【问题描述】:我正在使用phonegapFileAPI(FileWriter)将图像文... 查看详情

Phonegap 在 iOS 中使用 File-Transfer 下载文件并在设备中访问它

】Phonegap在iOS中使用File-Transfer下载文件并在设备中访问它【英文标题】:PhonegapDownloadfileiniOSwithFile-Transferandaccesstoitinthedevice【发布时间】:2015-07-2114:48:48【问题描述】:我使用Phonegap和jQueryMobile创建了一个应用程序,它在iPadmini... 查看详情

在 iOS Phonegap 应用程序中禁用“想使用您当前的位置”警报

】在iOSPhonegap应用程序中禁用“想使用您当前的位置”警报【英文标题】:Disable"WouldLiketoUseYourCurrentLocation"alertiniOSPhonegapapp【发布时间】:2014-02-0614:19:15【问题描述】:我正在开发一个phonegap应用程序,我删除了所有使用G... 查看详情

在 iOS 中使用 PhoneGap 检测 SIM 卡更改

】在iOS中使用PhoneGap检测SIM卡更改【英文标题】:DetectSIMchangeusingPhoneGapiniOS【发布时间】:2015-12-0914:28:38【问题描述】:我正在开发一个PhoneGapiOS应用程序,该应用程序需要使用SIM或MSISDN来实现某些功能。我想知道是否有任何方... 查看详情

如何在 iOS 中删除 Phonegap 构建权限警报?

】如何在iOS中删除Phonegap构建权限警报?【英文标题】:HowtoremovePhonegapBuildPermissionalertiniOS?【发布时间】:2015-05-2121:25:18【问题描述】:我正在使用PhonegapBuild来编译我使用Construct2制作的游戏。现在,当我在iPhone上安装游戏时,... 查看详情

在 PhoneGap 1.2.0 中使用 Google Analytics 时 Android 和 iOS 之间的差异

】在PhoneGap1.2.0中使用GoogleAnalytics时Android和iOS之间的差异【英文标题】:DifferencesbetweenAndroidandiOSwhenusingGoogleAnalyticsinPhoneGap1.2.0【发布时间】:2011-11-1113:24:12【问题描述】:我一直在尝试让GoogleAnalytics在Android和iOS上的PhoneGap1.2.0中... 查看详情

iOS 的 Phonegap 插件

】iOS的Phonegap插件【英文标题】:PhonegappluginsforiOS【发布时间】:2014-05-2507:22:00【问题描述】:在windows机器上使用“phonegap”(在mac上没试过)并为android构建“phonegap”项目时,所有插件都复制到src目录中,您可以在您的android编... 查看详情

如何使用地图:在phonegap ios应用程序中

】如何使用地图:在phonegapios应用程序中【英文标题】:howtousemaps:inphonegapiosapplication【发布时间】:2013-03-0805:31:55【问题描述】:参考link我正在尝试使用以下网址将给定位置定位到本机iOS地图上:window.location="maps:Greensboro+NC"但... 查看详情

使用 phonegap 防止键盘在 iOS 应用程序中向上推 webview

】使用phonegap防止键盘在iOS应用程序中向上推webview【英文标题】:PreventKeybordpushupwebviewatiOSappusingphonegap【发布时间】:2016-03-0909:37:05【问题描述】:每当我在iOS应用程序中单击文本字段或数据选择器时,导航栏都会随着滚动而向... 查看详情

div 标签在使用 PhoneGap 构建的 iOS 应用程序中是可选的

】div标签在使用PhoneGap构建的iOS应用程序中是可选的【英文标题】:divtagsareselectableiniOSappbuiltwithPhoneGap【发布时间】:2015-06-2521:09:10【问题描述】:我正在使用PhoneGap构建一个应用程序,我注意到div标签可以选择为以下有谁知道... 查看详情

在 Phonegap iOS 应用程序中使用预填充数据库

】在PhonegapiOS应用程序中使用预填充数据库【英文标题】:UsingPrepopulateddatabaseinPhonegapiOSapplication【发布时间】:2013-11-0317:54:38【问题描述】:我正在开发一个phonegapiOS应用程序,它的android版本已经推出。我们正在使用预填充数据... 查看详情