1

我在让 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”吗?</li>
  • 在“NSNotification *”类型的对象上找不到属性“pendingNotifications”-

我将 'pushHandler' 更改为 'onpushHandler' - 但我不知道这是否正确,因为插件的开发人员没有以第一种方式将其命名为 onpushHandler。

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

也许有人可以帮助我     

4

1 回答 1

1

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

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

导入“PushNotification.h”

我建议您通过查看此链接从头开始。

于 2013-04-03T07:48:49.063 回答