【发布时间】: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