Cordova phonegap 2.0推送通知插件iOS设置(一个接一个错误)
在过去的几周里,我们一直在尝试使用Phonegap 2基本应用程序设置PushNotification 这里是我所做的步骤Cordova phonegap 2.0推送通知插件iOS设置(一个接一个错误),cordova,push-notification,ios6,xcode4.5,Cordova,Push Notification,Ios6,Xcode4.5,在过去的几周里,我们一直在尝试使用Phonegap 2基本应用程序设置PushNotification 这里是我所做的步骤 将PushNotification文件夹拖到plugins文件夹: (来源:) 按照文档中的说明进行操作 (来源:) 将PushNotification/PushNotification添加到Cordova.plistplugins部分 修改AppDelegate.m: - (void) dealloc { [super dealloc]; } /* STAR
(来源:)
(来源:)
Cordova.plist
plugins部分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
#import "PushNotification.h"
这就解决了问题
下一个问题
找不到CDVPlugin.h文件
因此,我将以下内容添加到用户标题搜索路径-所有构建设置中:
$(CORDOVALIB)/Classes (recursive)
下一个问题
然后它抛出了20多个错误
(来源:) 我做错了什么 到处都在找。令我惊讶的是,似乎没有人有问题 有关我的设置的详细信息:
- Phonegap 2.0
- XCode 4.5(预览版4)
- iOS 6基本版(iOS 5及以上版本的应用程序版本)
/* 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 */
我所做的-前两个
-(无效)应用程序:(UIApplication*)应用程序
改为
-(无效)应用程序:(UIApplication*)应用程序
然后我移动
#导入“PushNotification.h”
到块的头部(而不是在修改代码之前-这会导致@end not in context问题)
我还没有运行javascript接口。但所有的错误都消失了
谢谢 请尝试还原对导入的更改,然后替换此块
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif
#ifdef CORDOVA#u框架
#进口
#否则
#导入“CDVPlugin.h”
#恩迪夫
按这条线
#import <Cordova/CDVPlugin.h>
#导入
如果这仍然不起作用,那么您可能没有PhoneGap 2.0项目,或者您安装了错误的或多个版本的框架
您可以在“PushNotification.m”文件中执行相同的操作:只需将第二次导入替换为#import
请注意,我还没有使用该插件,这是我移植到2.0的经验(我是选项卡/导航栏插件的作者)。感谢您的回答。你在这里说了什么,误差从20减少到5。稍后我将更新有关错误的更多信息。