I am updating an iOS application to work with iOS8, but I am having problems getting a device token for remote notifications.
I updated the AppDelegate app to call RegisterUserNotificationSettings to register when using iOS8, leaving the previous versions to call RegisterForRemoteNotificationTypes :
var version8 = new Version (8,0); if (new Version(UIDevice.CurrentDevice.SystemVersion) < version8) { var notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes); } else { var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet()); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); }
I also have the following methods in the AppDelegate class:
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { NSString str = (NSString)Runtime.GetNSObject(Messaging.intptr_objc_msgSend(deviceToken.Handle, new Selector("description").Handle)); _deviceTokenString = str.ToString().Replace("<", "").Replace(">", "").Replace(" ", ""); Trace.trace("Device Token: " + _deviceTokenString); }
and
public override void DidRegisterUserNotificationSettings(UIApplication application, UIUserNotificationSettings notificationSettings) {
However, I do not know how to get the device token in DidRegisterUserNotificationSettings
I read that in objective-c there is: didRegisterForRemoteNotificationsWithDeviceToken , but this does not seem to be available in Xamarin (or at least I don't know what to call it).
source share