-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can this be used with a UIViewController? #3
Comments
Hi, Sure you can! Make it 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! |
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
|
Cool! And on what line does the exception happen? -- while mobile On Nov 28, 2011, at 6:39 PM, Imran Ansarireply@reply.github.com 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]));
}
}
|
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 Ansarireply@reply.github.com 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 :) |
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, -- while mobile On Nov 28, 2011, at 7:25 PM, Imran Ansarireply@reply.github.com wrote:
|
How did this work out for you? |
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. On Dec 2, 2011, at 3:38 PM, Marcus Westin wrote:
|
i had a similar problem, but adding [callback copy] to registerObjcCallback worked (for now)
anyone can explain that? :) someone on stackoverflow posted that on a question about ios callbacks: http://stackoverflow.com/a/3915774/109219
|
@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 |
…oper.apple.com/library/ios/#documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html "Types of variables" #3 and #4 - we want callbackId to be non-mutable, const
Hi,
I'm trying to build a Hybrid app using the bridge (I'm literally a few days old in iOS dev) .
have a tabbar navigation based app, and I'm using a UIViewController for each tab view, one of the tab would use the WebView.
I wast sure if I could implement WebViewJavascriptBridgeDelegate in a UIViewController class like below.
@interface CurrentTimeViewController : UIViewController <UIWebViewDelegate, WebViewJavascriptBridgeDelegate>
I get a EXC_BAD_ACC during runtime in the main class
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Any pointer would be much appreciated.
-Imran
The text was updated successfully, but these errors were encountered: