Search code examples
iosobjective-cswiftcocoapodswbwebviewconsole

use_frameworks! for only some pods or swift pods


I have both Objective C and Swift Pods in my project.

pod 'WBWebViewConsole', '~> 1.0.1' 
use_frameworks! 
pod 'XWebView', '~>0.9.5’ 
pod 'Starscream', '~> 1.1.3'

As swift PODs(XWebView, Starscream) can only be added as frameworks I have to use use_frameworks!

But this makes all the PODs as framework including Objective-C PODs(WBWebViewConsole) as well.

But it causes problem with Objective-C POD but I don't intend to make Objective-C POD as framework.

So is there anyway I can ignore couple of PODs from being converted as framework ?

Thanks.

Update:

How to reproduce the problem ?

The problem is with the POD WBWebViewConsole

Run the attached project in any iOS 8+ devices that has internet connection as it loads a html doc from google drive.

in the html doc … click General/Info/Warning/Debug/Error Log

enter image description here

you will some text appearing on the html page whenever u click any of the above buttons….

The library is about capturing the logs that’s generated in html page…

Whenever u click the button apart from showing some text in html page I am writing some log in background.

enter image description here

Now click on the button get logs … and see the logs in Xcode IDE… you will see the all the console logs that’s generated in html

enter image description here

Get logs-> is a native button super imposed on webview..the library lets us read the console logs from wkwebview ..

Now in the POD u uncomment the following lines

use_frameworks!
pod 'PLCrashReporter'
pod 'XWebView', '~> 0.9.5’

and do pod install

then paste the following code on top of ViewController

import WBWebViewConsole

Here is the project with which has all this uncommented with all the changes required to reproduce the problem

now u run the project on device and click some buttons in html page and click get logs you can't see comments that's generated in the html page

To be specific below delegate methods implemented in WBWKWebView are not getting fired.

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
- (void)wb_evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(NSString *, NSError *))completionHandler

But while creating the instance of WBWKWebView and loading a URL all the necessary delegates of this class are getting fired.

The above delegates are supposed to fire when a log is written while clicking the button in html page


Solution

  • When JSBridge init, it will add some "UserScripts" to webview, which source is loaded from [NSBundle mainBundle] in previous version. But if it's in a framework, the resource files is in the framework bundle instead of mainBundle.

    So the fix is in WBWebViewConsoleDefines

    replace this

    inline static NSBundle * WBWebBrowserConsoleBundle()
    {
    return [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"WBWebBrowserConsole.bundle"]];
    }
    

    with

    inline static NSBundle * WBWebBrowserConsoleBundle()
    {
    return [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@/%@", [NSBundle bundleForClass:[WBWebViewConsole class]], @"WBWebBrowserConsole.bundle"]]; 
    }
    

    Actually the author has released new version it also has the fix

    pod 'WBWebViewConsole', '~> 1.0.2’

    1. pod install
    2. restart Xcode and clean your project
    3. build and run again

    Note: Its not possible. if you use_frameworks! everything become dynamic framework.