0
xamarin iOSリモート通知ガイドに従って、iOS開発証明書とAPN開発証明書の2つの証明書を作成しました。 私のキーチェーンアクセスでは、2つの証明書とキーもあります。ガイドで要求されたため、キーをデスクトップにエクスポートしました。 REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTIONリモート通知をテストするためのiOSシミュレータを使用しないでくださいXamarin.iOS:リモート通知iOSが動作しない
[Register ("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0))
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings (pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
}
global::Xamarin.Forms.Forms.Init();
LoadApplication (new App());
return base.FinishedLaunching (app, options);
}
/// <summary>
///
/// </summary>
public override void ReceivedLocalNotification (UIApplication application, UILocalNotification notification)
{
// show an alert
new UIAlertView(notification.AlertAction, notification.AlertBody, null, "OK", null).Show();
// reset our badge
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
}
public override void ReceivedRemoteNotification (UIApplication application, NSDictionary userInfo)
{
}
/// <summary>
/// The iOS will call the APNS in the background and issue a device token to the device. when that's
/// accomplished, this method will be called.
///
/// Note: the device token can change, so this needs to register with your server application everytime
/// this method is invoked, or at a minimum, cache the last token and check for a change.
/// </summary>
public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
{
// Get current device token
var DeviceToken = deviceToken.Description;
if (!string.IsNullOrWhiteSpace(DeviceToken)) {
DeviceToken = DeviceToken.Trim('<').Trim('>');
}
// Get previous device token
var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");
// Has the token changed?
if (string.IsNullOrEmpty(oldDeviceToken) || !oldDeviceToken.Equals(DeviceToken))
{
//TODO: Put your own logic here to notify your server that the device token has changed/been created!
}
// Save new device token
NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
}
/// <summary>
/// Registering for push notifications can fail, for instance, if the device doesn't have network access.
///
/// In this case, this method will be called.
/// </summary>
public override void FailedToRegisterForRemoteNotifications (UIApplication application , NSError error)
{
new UIAlertView("Error registering push notifications", error.LocalizedDescription, null, "OK", null).Show();
}
}
この投稿の2番目の回答は役に立ちます。 http://stackoverflow.com/questions/32705645/unable-to-register-for-push-notifications-xcode-7-ios9 –
私はシミュレータで作業していましたが、私は実際のデバイスを使用してこの問題を解決しました –