IOS device device token

I use Monotouch for mac and followed the steps to get a provisioning profile certificate that allows push notification in the process. I have a working application, and now I'm experimenting with apns-sharp and moon-apns, but I can’t figure out how to get the token of my device . I hope someone can provide me with detailed and simple steps to achieve this.

+6
source share
1 answer

In your FinishedLaunching method, register the application for remote notifications through the UIApplication object that you get in it:

 // Pass the UIRemoteNotificationType combinations you want app.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound); 

Then, in the AppDelegate class AppDelegate override the RegisteredForRemoteNotifications method:

 public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken) { // The device token byte[] token = deviceToken.ToArray(); } 

You must also override the FailedToRegisterForRemoteNotifications method to handle the error, if any:

 public override void FailedToRegisterForRemoteNotifications (UIApplication application, NSError error) { // Do something with the error } 
+4
source

Source: https://habr.com/ru/post/910576/


All Articles