2

Я пытаюсь добавить уведомление толчка в моем приложении Xamarin.iOS с помощью этого учебника https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-startedXamarin.iOS Нажмите уведомление от Notification Hub Azure

Я все шагов, как это и ниже, что я пытался до сих пор: -

AppDelegate.cs

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 
    { 
    // create a new window instance based on the screen size 
    Window = new UIWindow(UIScreen.MainScreen.Bounds); 
    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); 
    } 


    // If you have defined a root view controller, set it here: 
    UIStoryboard storyboard = UIStoryboard.FromName("Main", null); 
    var myViewController = storyboard.InstantiateViewController("Login_VC") as LoginViewController; 
    Window.RootViewController = myViewController; 

    // make the window visible 
    Window.MakeKeyAndVisible(); 



    return true; 
    } 

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
    { 
    Hub = new SBNotificationHub(ServiceConstants.ListenConnectionString, ServiceConstants.NotificationHubName); 

    string token = deviceToken.ToString().Replace("<", "").Replace(">", "").Replace(" ", ""); 

    deviceToken = NSData.FromString(token); 
    Hub.UnregisterAllAsync(deviceToken, (error) => 
    { 
    if (error != null) 
    { 
    Console.WriteLine("Error calling Unregister: {0}", error.ToString()); 
    return; 
    } 

    NSSet tags = null; // create tags if you want 
    Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => 
    { 
    if (errorCallback != null) 
     Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString()); 
    }); 
    }); 




    } 

Я подписал мое приложение с профилем обеспечения разработки из консоли разработчика яблока, который подписывается с AppId с Push-уведомления позволяют d на нем.

Но когда я получаю сообщение об ошибке в самом начале при регистрации для уведомления толчка следующим образом: -

Error Response:<Error><Code>401</Code><Detail>ExpiredToken: .TrackingId:94e8c47b-1221-4188-8a75-9b744e12c9d7_G4,TimeStamp:1/20/2017 10:05:51 AM</Detail></Error> 
Fail to perform registration operation. 
<NSMutableURLRequest: 0x170018a70> { URL: https://mynotificationnamespace.servicebus.windows.net/mynotificationhub/Registrations/?$filter=deviceToken+eq+'62383062663335386437646233313263613766656165323535626634646537393438623262616238393164393466393766353030666166313966623339323232'&api-version=2013-04 } 
Headers:{ 
    Authorization = "SharedAccessSignature sr=http%3a%2f%2fmynotificationnamespace.servicebus.windows.net%2fmynotificationhub%2fregistrations%2f%3f%24filter%3ddevicetoken%2beq%2b%2762383062663335386437646233313263613766656165323535626634646537393438623262616238393164393466393766353030666166313966623339323232%27%26api-version%3d2013-04&sig=dpGnfYj19D%2FseR3GlTrE6Ay0ASdc%2BwFwWRNf3sxBE0%3D&se=148394919&skn=DefaultListenSharedAccessSignature"; 
    "Content-Type" = "application/xml"; 
    "User-Agent" = "NOTIFICATIONHUBS/2013-04(api-origin=IosSdk; os=iOS; os_version=10.2;)"; 
} 

Я смог получить Push-уведомлений, работающих с одной и той же Notification хаб для Xamarin.Android, но не Xamarin.iOS.

Любая помощь будет оценена по достоинству.

ответ

1

Ответ на мой вопрос, поскольку он может быть полезен людям, которые ищут что-то подобное. Оказывается, автоматическое DateTime было отключено на моем устройстве, поэтому токен устройства извлекался как недействительный или истек, поскольку время на устройстве отставало с 30 минутами.

Смежные вопросы