0
xamarin iOS 원격 알림 가이드에 따라 iOS 개발 인증서와 APN의 개발 인증서 2 가지 인증서를 만들었습니다. 내 키 체인 액세스에서 인증서와 키가 2 개 있습니다. 가이드에서 요청했기 때문에 키를 데스크톱으로 내 보냈습니다. 하지만 내 응용 프로그램Xamarin.iOS : 원격 알림 iOS가 작동하지 않습니다.
오류 열 때 나는이 오류가 발생했습니다 : REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION
[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();
}
}
이 게시물의 두 번째 대답은 당신을 도울 수 있습니다
는이 참조하십시오. http://stackoverflow.com/questions/32705645/unable-to-register-for-push-notifications-xcode-7-ios9 –
나는 시뮬레이터로 작업 중이 었는데 실제 장치를 사용하여이 문제를 해결했습니다. –