过去几周一直在尝试使用 Phonegap 2 基础应用程序设置 PushNotification。
这是我已经完成的步骤。
将 PushNotification 文件夹拖到 plugins 文件夹中:
(来源:joelchu.com)按照文档的以下说明进行操作
(来源:joelchu.com)将 PushNotifcation / PushNotification 添加到
Cordova.plist
插件部分修改
AppDelegate.m
:- (void) dealloc { [super dealloc]; } /* START PUSH MODIFCATION */ #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"]; [pushHandler didReceiveRemoteNotification:mutableUserInfo]; } else { [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"]; [pushHandler.pendingNotifications addObject:mutableUserInfo]; } } /* END PUSH MODIFICATION */ @end
第一个错误
未知类型名称 PushNotification
所以我在最后一次导入之后添加了这一行:
#import "PushNotification.h"
这样就解决了问题。
下一个问题
未找到 CDVPlugin.h 文件
因此,我将以下内容添加到 User Header Search Paths - 所有构建设置中:
$(CORDOVALIB)/Classes (recursive)
下一个问题
然后它抛出了20多个错误!
(来源:joelchu.com)
我做错了什么?
一直在到处寻找。令我惊讶的是,似乎没有人有问题。
更多关于我的设置:
- 电话间隙 2.0
- XCode 4.5(预览版 4)
- iOS 6 基础版(适用于 iOS 5 及更高版本的应用程序)
希望有大神解答一下。谢谢你。
(PS如果Phonegap PushNotification插件坏了——他们已经4个月没有更新了。有没有免费的替代品?再次感谢)
我在我的博客上描述了同样的问题。
已修复(暂时)
固定的
/* START BLOCK */
#pragma PushNotification delegation
- (void) application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"];
[pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void) application:(UIApplication*)application 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"];
[pushHandler didReceiveRemoteNotification:mutableUserInfo];
} else {
[mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"];
[mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"];
[pushHandler.pendingNotifications addObject:mutableUserInfo];
}
}
/* STOP BLOCK */
我做了什么——前两个
- (void)application:(UIApplication*)app
变成
- (void) application:(UIApplication*)application
我移动
#import "PushNotification.h"
到块的头部(而不是在修改代码之前 - 导致@end不在上下文问题中)。
我还没有运行javascript界面。但是所有的错误都消失了。
谢谢。