2016-08-08 5 views
0

Xamarin Forms에서 푸시 알림을 사용하는 데 어려움을 겪고 있습니다. 도움을 주시면 감사하겠습니다.Xamarin Forms Azure 알림 허브로 푸시 알림

나는 그 자체로 오래된 것으로 보이는 this 튜토리얼을 팔로우하고 있습니다.

저는 현재 iOS와 관련이 있습니다. 여기에 내가 한 일이있다 :

나는 Azure에 App Service를 설치하고 그것을위한 Notification Hub를 만들었다. 필자는 Apple 개발자 센터를 통해 APNS 인증서를 작성하고 Apple Push Notification에 필요한 경우 Notification Hub에 업로드했습니다. 내 기기에서 앱을 실행하기 위해 서명하는 데 필요한 프로비저닝 프로파일 인증서가 있습니다. 어딘가

Push push = AppContainer.MobileServiceClient.GetPush(); 

그 라인은 기본적으로이

var client = new MobileServiceClient(APIConstants.PUSH_NOTIFICATION_URL); 
의 래퍼 인 문제는이 라인이라고 나는 생각

public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
    { 
     global::Xamarin.Forms.Forms.Init(); 
     var setup = new IOSAppContainerSetup(); 
     LoadApplication (new App (setup)); 

     // Register for push notifications. 
     var settings = UIUserNotificationSettings.GetSettingsForTypes(
      UIUserNotificationType.Alert 
      | UIUserNotificationType.Badge 
      | UIUserNotificationType.Sound, 
      new NSSet()); 

     UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); 
     UIApplication.SharedApplication.RegisterForRemoteNotifications(); 

     return base.FinishedLaunching (app, options); 
    } 

    public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
    { 
     const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}"; 

     JObject templates = new JObject(); 
     templates["genericMessage"] = new JObject 
     { 
      {"body", templateBodyAPNS} 
     }; 

     // Register for push with your mobile app 
     Push push = AppContainer.MobileServiceClient.GetPush(); 
     push.RegisterAsync(deviceToken, templates); 
    } 


    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) 
    { 
     UIAlertView avAlert1 = new UIAlertView("Notification", "Got something", null, "OK", null); 
     avAlert1.Show(); 

     NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary; 

     string alert = string.Empty; 
     if (aps.ContainsKey(new NSString("alert"))) 
      alert = (aps[new NSString("alert")] as NSString).ToString(); 

     //show alert 
     if (!string.IsNullOrEmpty(alert)) 
     { 
      UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null); 
      avAlert.Show(); 
     } 
    } 

: 여기

는 내 AppDelegate에 클래스 코드

이것은 앱의 다른 곳에서 수행됩니다. 나는 잘못된 URL을 사용할 수 있다고 의심하지만 아무것도 분명하지 않습니다. 나는 App Service와 Notification Hub 끝점의 URL을 시도해 보았습니다. 다양한 형태, 즉 프로토콜 삭제, 후행 슬래시 삭제 등을 시도했습니다.

아무것도 작동하는 것 같다없고, 내가 말했듯이 내가

: 내 머리를 찢어있어 점에있어, 튜토리얼의 유효 기간이 될 것, 그리고 내가 찾은 다른 자습서 똑같이 부족하다. Azure 포털을 통해 알림 허브 아래에있는 테스트 보내기 옵션을 통해 직접 테스트 중이지만 아무 것도 장치로 보내지 않거나 적어도 장치가 알림을 표시하지 않습니다.

도움이 될 것입니다. 혹시 더 유용한 튜토리얼을 온라인 어딘가에서 찾았 으면 저에게 링크를 보내주십시오.

답변

0

제 질문에 언급 한 자습서가 잘못되었거나 불완전한 것 같습니다. 코드 here을 따라 푸시 알림을받을 수있었습니다. Xamarin 팀의 Mike가 친절하게 링크를 제공했습니다.

환호성 Mike!