【问题标题】:Cordova 2.5.0 - Errors after referencing appDelegate.m to PushPluginCordova 2.5.0 - 将 appDelegate.m 引用到 PushPlugin 后出现错误
【发布时间】:2013-04-02 17:12:55
【问题描述】:

在 Xcode 中让 PushNotification-Plugin 工作时遇到了一些麻烦。 这是我到目前为止所做的(直到最后一点都没有错误):

  • 我从https://github.com/phonegap-build/PushPlugin/下载了最新的插件
  • 我将 PushNotification 文件夹拖放到 XCode 中的 Plugins 文件夹并选中 “为任何添加的文件夹创建组”作为复制选项
  • 将 Xcode 外部的 PushNotification.js 复制到我项目的 www 文件夹中
  • 在我的 HTML 文件中添加了一个脚本标记来引用 PushNotification.js 文件
  • 在 config.xml 中添加了插件 name="PushPlugin" 和 value="PushPlugin"

还没有错误(虽然我认为它可能有用,但你知道,我已经做了什么)

好的,现在开始出现错误: 我将此代码块与这些方法添加到我的 AppDelegate.m

#pragma PushNotification delegation

- (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
[pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication*)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
[pushHandler didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy];

// Get application state for iOS4.x+ devices, otherwise assume active
UIApplicationState appState = UIApplicationStateActive;

    if ([application respondsToSelector:@selector(applicationState)]) {
    appState = application.applicationState;
    }
    [mutableUserInfo setValue:@"0" forKey:@"applicationLaunchNotification"];

    if (appState == UIApplicationStateActive) {
    [mutableUserInfo setValue:@"1" forKey:@"applicationStateActive"];
    } else {
    [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"];
    [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] 
    timeIntervalSince1970]] forKey:@"timestamp"];
    [pushHandler.pendingNotifications addObject:mutableUserInfo];
    }
 }

所以这是我收到的错误:

  • 使用未声明的标识符“pushHandler”;您的意思是“onpushHandler”吗?
  • 未知类型名称“PushNotification”;你的意思是“NSNotification”吗?
  • 在“NSNotification *”类型的对象上找不到属性“pendingNotifications” -

我把 'pushHandler' 改成了 'onpushHandler' - 但我不知道这样对不对,因为插件的开发者并没有以第一种方式将它命名为 onpushHandler。

对于另外两件事,我不知道通过将其更改为 NSNotification 是否是正确的处理方式

也许有人可以帮助我

【问题讨论】:

    标签: plugins push-notification cordova xcode4.5 appdelegate


    【解决方案1】:

    检查 xcode 中的 Pushnotification 文件夹,它是否有“Pushnotification.m”文件或“PushPlugin.m”文件。 如果是 PushPlugin.m 文件,则不要复制 AppDelgate.m 文件中的代码。从 github 复制 AppDelegate

    如果是 PushNotification.m 文件,则只需在 AppDelegate.m 文件顶部添加代码

    导入“PushNotification.h”

    我建议您通过查看 link 从头开始​​。

    【讨论】:

    • 非常感谢林森。但是在具有最新 PushNotifications-PLugin 的 github 中没有 AppDelegate - 我应该复制什么?
    • 太棒了,谢谢。我正在考虑在她的博客上给 Holly 写一条评论。这似乎是我正在寻找的代码。
    • 我试图投票给你,但我没有足够的声誉 - 但再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多