Using Objective-C From JavaScript
Using Objective-C From JavaScript
- Subject: Using Objective-C From JavaScript
- From: Chad Rosenberg <email@hidden>
- Date: Thu, 10 Nov 2005 11:59:32 -0800 (PST)
I was trying to follow the "Using Objective-C From JavaScript" example on
http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html
and I can't seem to get it to work. When I run the following:
function printNameAtIndex(index) {
var myaddressbook = window.AddressBook;
var name = myaddressbook.nameAtIndex_(index);
document.write(name);
}
typeof(window.AddressBook) returns "function" and
myaddressbook.nameAtIndex_ is undefinied.
I set up the AddressBook in an awakeFromNib method:
- (void)awakeFromNib
{
BasicAddressBook *littleBlackBook = [BasicAddressBook
addressBook];
id win = [webView windowScriptObject];
[win setValue:littleBlackBook forKey:@"AddressBook"];
NSString* url = @"file:///tmp/test.html";
[[webView mainFrame] loadRequest:[NSURLRequest
requestWithURL:[NSURL URLWithString:url]]];
NSLog(@"awake");
}
The above properly displays the test.html, and
[win setValue:littleBlackBook forKey:@"AddressBook"] seems to doing
something, since without it "window.AddressBook" becomes undefined in
the Java Script.
Any help would be appriciated.
Thanks,
Chad
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden