2

I have a PhoneGap app up and running using JavaScript and HTML.

On app startup I need to run some Objective C code (I don't know anything about Objective C. I just have some code that I need to copy + paste so it runs when the app starts).

Where do I put that code in my Phonegap project? Is there some kind of event listener or a main function?

4

2 回答 2

4

在您的 AppDelegate.m 文件中查找名为:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //ADD YOUR OBJECTIVE-C CODE HERE
    return YES;
}

另一种可能的选择:

您可能还有其他类,例如 XXXViewController.h/.m。如果是这种情况,请检查是否有一个方法称为:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //INSERT YOUR OBJECTIVE-C CODE HERE.
}
于 2012-08-14T14:30:56.157 回答
1

您需要使用插件。通过这样做,您可以创建本机目标 C 类,然后从 PhoneGap 中的 Javascript 调用它们。

看看这里: http: //www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios.html

于 2012-08-14T14:06:04.170 回答