Xamarin iOS SDK
要将 Pushwoosh 集成到您的 Xamarin iOS 应用程序中:
1. 将 Pushwoosh.Xamarin.iOS nuget 软件包添加到您的解决方案中。
2. 在您的项目中,打开 AppDelegate.cs 并通过添加 using Pushwoosh 行来连接 Pushwoosh。
3. 在您的 Info.plist 中,添加 Pushwoosh_APPID 键,并将其值设置为您的 Pushwoosh 应用程序 ID 字符串。
4. 组织以下导入:
- using Pushwoosh;
- using UserNotifications;
5. 将以下方法添加到 AppDelegate 类中:
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken){ PushNotificationManager.PushManager.HandlePushRegistration (deviceToken);}
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error){ PushNotificationManager.PushManager.HandlePushRegistrationFailure (error);}
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo){ PushNotificationManager.PushManager.HandlePushReceived (userInfo);}6. 将以下代码添加到 public override bool FinishedLaunching(UIApplication app, NSDictionary launchOptions) 方法中:
PushNotificationManager pushmanager = PushNotificationManager.PushManager;pushmanager.Delegate = new PushDelegate();UNUserNotificationCenter.Current.Delegate = pushmanager.notificationCenterDelegate;
if (options != null) { if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { pushmanager.HandlePushReceived(options); }}
pushmanager.RegisterForPushNotifications();7. 将以下类添加到 AppDelegate 中:
public class PushDelegate : PushNotificationDelegate { public override void OnPushAccepted(PushNotificationManager pushManager, NSDictionary pushNotification) { Console.WriteLine("Push accepted: " + pushNotification); }
public override void OnPushReceived(PushNotificationManager pushManager, NSDictionary pushNotification, bool onStart) { Console.WriteLine("Push received: " + pushNotification); }
public override void OnDidRegisterForRemoteNotificationsWithDeviceToken(NSString token) { Console.WriteLine("Registered for push notifications: " + token); }
public override void OnDidFailToRegisterForRemoteNotificationsWithError(NSError error) { Console.WriteLine("Error: " + error); } }与我们分享您的反馈
Anchor link to您的反馈有助于我们创造更好的体验,因此如果您在 SDK 集成过程中遇到任何问题,我们很乐意听取您的意见。如果您遇到任何困难,请随时通过此表单与我们分享您的想法。