最后我找到了方法。它现在工作。我从他们网站的教程中得到了代码。
所以我正在写步骤。
第 1 步 - 将 Push NotificationsSDK 添加到您的项目中
第 2 步 - 在 Info.plist 中添加以下密钥 Pushwoosh_APPID 和您的 Pushwoosh id
第 3 步 - 在其他链接器标志中添加 -ObjC 和 -all_load。(例如下文)。
第 4 步 - 在 AppDelegate.h 中添加以下代码
**#import "Pushwoosh/PushNotificationManager.h"**
@interface AppDelegate : UIResponder <UIApplicationDelegate,**PushNotificationDelegate**>
第 5 步 - 在 AppDelegate.m 中添加以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Your Other Code
[PushNotificationManager pushManager].delegate = self;
[[PushNotificationManager pushManager] handlePushReceived:launchOptions];
[[PushNotificationManager pushManager] sendAppOpen];
[[PushNotificationManager pushManager] registerForPushNotifications];
}
下面给出了推送通知的代表
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[PushNotificationManager pushManager] handlePushRegistration:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[PushNotificationManager pushManager] handlePushRegistrationFailure:error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[PushNotificationManager pushManager] handlePushReceived:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSDictionary *pushDict = [userInfo objectForKey:@"aps"];
BOOL isSilentPush = [[pushDict objectForKey:@"content-available"] boolValue];
if (isSilentPush) {
NSLog(@"Silent push notification:%@", userInfo);
//load content here
// must call completionHandler
completionHandler(UIBackgroundFetchResultNewData);
}
else {
[[PushNotificationManager pushManager] handlePushReceived:userInfo];
// must call completionHandler
completionHandler(UIBackgroundFetchResultNoData);
}
}
- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification
{
NSLog(@"Push notification received");
}