0

푸시 알림을 내 양식 응용 프로그램과 통합하려고했습니다. Azure 메시징 구성 요소는이를 달성하는 데 사용됩니다. 아래 코드는 제가 사용하고있는 코드입니다. 나는 RegisteredForRemoteNotifications 방법에 방아쇠를 얻고있다. 그러나 RegisterNativeAsync 방법은 작업을 수행하지 않는 것 같습니다.Xamarin Forms에서 Azure 푸시 알림 서비스를 구독하십시오.

public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
{ 
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 
{ 
var push = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, 
new NSSet()); 
UIApplication.SharedApplication.RegisterUserNotificationSettings(push); 
UIApplication.SharedApplication.RegisterForRemoteNotifications(); 
} 
else 
{ 
const UIRemoteNotificationType not = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; 
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(not); 
} 
} 

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
{ 

     Hub = new SBNotificationHub(conStirng, NotifHubPath); 
     Hub.UnregisterAllAsync(deviceToken, (error) => 
     { 
      //Get device token 
      var id = deviceToken.ToString(); 
      var tag = "username"; 
      var tags = new List<string> { tag }; 
      Hub.RegisterNativeAsync(id, new NSSet(tags.ToArray()), (errorCallback) => 
      { 
       if (errorCallback != null) 
       { 
        //Log to output 
       } 
      }); 
     }); 
    } 

여기서 내가 뭘 잘못하고 있니? 등록 기능이 성공 또는 실패인지 어떻게 확인할 수 있습니까?

답변

0

등록 메소드의 응답으로 인한 오류가 null인지 확인해야합니다. null 경우 성공을 의미합니다.

var hub = new SBNotificationHub (cs, "your-hub-name"); 
    hub.RegisterNativeAsync (deviceToken, null, err => { 
     if (err != null) 
      Console.WriteLine("Error: " + err.Description); 
     else 
      Console.WriteLine("Success"); 
    }); 

Windows 범용 앱의 경우 응답의 registrationId 속성을 확인할 수 있습니다.

private async void InitNotificationsAsync() 
{ 
    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); 

    var hub = new NotificationHub("<hub name>", "<connection string with listen access>"); 
    var result = await hub.RegisterNativeAsync(channel.Uri); 

    // Displays the registration ID so you know it was successful 
    if (result.RegistrationId != null) 
    { 
     var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); 
     dialog.Commands.Add(new UICommand("OK")); 
     await dialog.ShowAsync(); 
    } 

} 
+0

Null이 성공 했습니까? – TutuGeorge

+0

오류가 없음을 의미합니다. 따라서 성공. – Aravind

관련 문제