phonegap 2.0推送通知插件iOS设置(一个接一个出错)
过去几周一直试图在Phonegap 2基本应用中设置PushNotification。phonegap 2.0推送通知插件iOS设置(一个接一个出错)
这里我已经完成的步骤。
-
拖动PushNotification文件夹,插件文件夹:
-
按照每个文档下面的指令
添加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找不到文件
所以我以下内容添加到用户头搜索路径 - 以所有构建设置:
$(CORDOVALIB)/Classes (recursive)
下一个问题
然后它抛出了20多个错误!
http://joelchu.com/wp-content/uploads/2012/09/3.png
我做了什么错?
一直在上下寻找。令我惊讶的是似乎没有人有问题。
更多关于我的设置:
- 的PhoneGap 2.0
- 的XCode 4。5(预览4)
- 的iOS 6基地(应用程序建立的iOS 5及以上)
希望有人在那里得到了一个答案。谢谢。
(如附注:在PhoneGap的PushNotification插件被打破 - 他们没有连续4个月已经再次更新是否有任何免费的替代感谢。?)
我所描述的my blog同样的问题。
固定(NOW)
固定
/* 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界面。但所有的错误都消失了。
谢谢。
请尝试通过这条线
#import <Cordova/CDVPlugin.h>
恢复您的更改进口,然后替换该块
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif
如果仍然不能正常工作,你可能没有的PhoneGap 2.0项目或你安装了错误或多个版本的框架。
您可以在“PushNotification.m”文件中执行同样的操作:只需用#import <Cordova/JSONKit.h>
替换第二个导入即可。
请注意,我还没有使用该插件,这只是从我移植到2.0的经验(我是制表符/导航栏插件的作者)。
感谢您的回答。你在这里说了什么,并且错误从20减少到了5.我将在稍后更新关于错误的更多信息。 –