我在Xcode中使用PushNotification-Plugin时遇到了一些麻烦。 这是我到目前为止所做的事情(直到最后一点才出现错误):
还没有错误(虽然我认为它可能有用,你知道,我已经做了什么)
好了,现在错误开始了: 我将这些代码块添加到我的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' - 但我不知道这是否正确,因为该插件的开发人员没有以第一种方式将其命名为onpushHandler。
对于其他两件事,我不知道是否通过将其更改为NSNotification来处理它是正确的方法
也许有人可以帮助我
答案 0 :(得分:1)
检查xcode中的Pushnotification文件夹,是否有“Pushnotification.m”文件或“PushPlugin.m”文件。 如果是PushPlugin.m文件,则不要将此代码复制到AppDelgate.m文件中。从github复制AppDelegate
如果是PushNotification.m文件,那么只需在AppDelegate.m文件顶部添加代码
我建议您从头开始查看link。