Comments (11)
Hi,
Sure you can! Make it @interface CurrentTimeViewController : UIViewController <WebViewJavascriptBridgeDelegate>
, and then implement - (void) handleMessage:(NSString*) message fromWebView: (UIWebView *)theWebView;
in the view controller.
Posting more of your code would make it easier to help you.
Also, are you sure the issue is in the WebViewJavascriptBridge code? Maybe you could start with the provided example and then start modifying your code from there?
Cheers!
from webviewjavascriptbridge.
Thanks for the response, When I use your example code as is, and hook in my web page, it works fine and I can invoke commands both ways, but below is my interface and implementation using a UIController with a tab nav, please have a look.
#import <Foundation/Foundation.h>
#import "WebViewJavascriptBridge.h"
@interface CurrentTimeViewController : UIViewController <WebViewJavascriptBridgeDelegate>
@property (strong, nonatomic) WebViewJavascriptBridge *javascriptBridge;
@property (strong, nonatomic) UIWebView *webView;
@end
Impl
#import "CurrentTimeViewController.h"
@implementation CurrentTimeViewController
@synthesize javascriptBridge;
@synthesize webView;
- (id)init
{
// Call the superclass's designated initializer
self = [super initWithNibName:nil
bundle:nil];
if (self) {
// Get the tab bar item
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@"Search"];
}
return self;
}
- (void)viewDidLoad
{
NSLog(@"Loaded the view for CurrentTime controller");
[super viewDidLoad];
webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:4567/form"]]];
javascriptBridge = [WebViewJavascriptBridge javascriptBridge];
javascriptBridge.delegate = self;
webView.delegate = javascriptBridge;
[javascriptBridge sendMessage:@"HI" toWebView:webView];
[self.view addSubview:webView];
[webView release];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
}
- (void)handleMessage:(NSString *)message fromWebView:(UIWebView *)theWebView {
NSLog(@"ExampleWebViewJavascriptBridgeDelegate received message: %@", message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"JSON passed from WebView"
message: message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
@end
from webviewjavascriptbridge.
Cool! And on what line does the exception happen?
-- while mobile
On Nov 28, 2011, at 6:39 PM, Imran [email protected] wrote:
Thanks for the response, When I use your example code as is, and hook in my web page, it works fine and I can invoke commands both ways, but below is my interface and implementation using a UIController with a tab nav, please have a look.
#import <Foundation/Foundation.h> #import "WebViewJavascriptBridge.h" @interface CurrentTimeViewController : UIViewController <WebViewJavascriptBridgeDelegate> @property (strong, nonatomic) WebViewJavascriptBridge *javascriptBridge; @property (strong, nonatomic) UIWebView *webView; @endImpl
#import "CurrentTimeViewController.h" @implementation CurrentTimeViewController @synthesize javascriptBridge; @synthesize webView; - (id)init { // Call the superclass's designated initializer self = [super initWithNibName:nil bundle:nil]; if (self) { // Get the tab bar item UITabBarItem *tbi = [self tabBarItem]; [tbi setTitle:@"Search"]; } return self; } - (void)viewDidLoad { NSLog(@"Loaded the view for CurrentTime controller"); [super viewDidLoad]; webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:4567/form"]]]; javascriptBridge = [WebViewJavascriptBridge javascriptBridge]; javascriptBridge.delegate = self; webView.delegate = javascriptBridge; [javascriptBridge sendMessage:@"HI" toWebView:webView]; [self.view addSubview:webView]; [webView release]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { } - (void)handleMessage:(NSString *)message fromWebView:(UIWebView *)theWebView { NSLog(@"ExampleWebViewJavascriptBridgeDelegate received message: %@", message); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"JSON passed from WebView" message: message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } @end
Reply to this email directly or view it on GitHub:
#3 (comment)
from webviewjavascriptbridge.
I get a EXC_BAD_ACCESS in the return statement below.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
from webviewjavascriptbridge.
Well, I can help you much easier if you track down which line in your application code is causing the error. Help me help you a bit here :)
For example, add a bunch of NSLog statements in your application unit initialization code - when you get to a log statement that didn't execute, one of the lines before it will likely be your culprit!
-- while mobile
On Nov 28, 2011, at 7:09 PM, Imran [email protected] wrote:
I get a EXC_BAD_ACCESS in the return statement below.
#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
Reply to this email directly or view it on GitHub:
#3 (comment)
from webviewjavascriptbridge.
Let me run through the debugger again, and come back to you on what I find, I havent tried debuggigng the AppDelegate yet.
Just downloaded 13 hrs worth of ObjectiveC from iDeveloper.tv, hope that helps, hate being a newb :)
from webviewjavascriptbridge.
Totally - enjoy!
I'm fairly new to iOS development myself so I may not be the best person to ask.
You'll probably find that some of your app delegate code is getting executed, and that somewhere down that stack there is a bad reference to something that haven't been alloced or something like that.
Cheers,
Marcus
-- while mobile
On Nov 28, 2011, at 7:25 PM, Imran [email protected] wrote:
Let me run through the debugger again, and come back to you on what I find, I havent tried debuggigng the AppDelegate yet.
Just downloaded 13 hrs worth of ObjectiveC from iDeveloper.tv, hope that helps, hate being a newb :)
Reply to this email directly or view it on GitHub:
#3 (comment)
from webviewjavascriptbridge.
How did this work out for you?
from webviewjavascriptbridge.
I couldn't, below is the link to the example app I was trying, see if you can figure out why it crashes, I couldn't even debug it.
https://github.com/imranansari/Tabstarter1
thanks for your help.
Imran
On Dec 2, 2011, at 3:38 PM, Marcus Westin wrote:
How did this work out for you?
Reply to this email directly or view it on GitHub:
#3 (comment)
from webviewjavascriptbridge.
i had a similar problem, but adding [callback copy] to registerObjcCallback worked (for now)
- (void)registerObjcCallback:(NSString *)name withCallback:(void (^)(NSDictionary *params))callback {
[self.javascriptCallbacks setObject:[callback copy] forKey:name];
}
anyone can explain that? :) someone on stackoverflow posted that on a question about ios callbacks: http://stackoverflow.com/a/3915774/109219
// NOTE: copying is very important if you'll call the callback asynchronously,
// even with garbage collection!
from webviewjavascriptbridge.
@hpoul Added your change in 287384d. Also, see http://stackoverflow.com/questions/4664804/why-does-the-assignment-of-an-objc-block-have-to-be-copy-not-assign
from webviewjavascriptbridge.
Related Issues (20)
- this project is in maintenance? 项目不在维护了吗? HOT 1
- 提交审核被拒,因为使用了UIWebView,有办法解决吗? HOT 8
- iOS UIWebview replacement to WKWebview HOT 4
- Web view is blank after creating the bridge object HOT 1
- iOS14.6 WebViewJavascriptBridge not work but iOS14.3 works HOT 1
- Hello
- Why don't work in iPad Air (14.1) ? HOT 2
- nice
- iOS 15.4 js 交互不走decidePolicyFor 这个代理方法了 HOT 2
- Mac OSX app Packages printed in version 10.15 and above crashed in system 10.14 and below, so far the problem has not been located HOT 1
- nice
- nice
- 我已经重构了这个库,10分钟就能完成接入,也许可以帮助你. HOT 2
- 按照README 第四步拷贝的js代码可能不起作用 HOT 1
- failed assertion `Draw Errors Validation
- Mambamessage
- Installed with CocoaPods in Xcode 15 beta 6 can not build module 'WebKit' HOT 9
- I think that if you no longer maintain this library, then it is recommended that you make this warehouse archived, rather than leave it to grow grass!
- JSBridge H5调用原生的方法,频繁调用的性能优化
- iOS17.1.1 收不到回调 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webviewjavascriptbridge.