1

Following this tutorial我创建了azure通知中心并添加到我的应用程序注册中。我的应用程序注册远程通知成功,当我试图在后端注册设备时,我成功获得了我的安装ID。Azure通知中心不适用于ios

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
{ 
MobileServiceClient client = QSTodoService.DefaultService.GetClient; 

const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}"; 

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

// Register for push with your mobile app 
var push = client.GetPush(); 
push.RegisterAsync(deviceToken, templates); 
} 

但是,当尝试发送通知

 // Get the settings for the server project. 
     HttpConfiguration config = this.Configuration; 
     MobileAppSettingsDictionary settings = 
      this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); 

     // Get the Notification Hubs credentials for the Mobile App. 
     string notificationHubName = settings.NotificationHubName; 
     string notificationHubConnection = settings 
      .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; 

     // Create a new Notification Hub client. 
     NotificationHubClient hub = NotificationHubClient 
     .CreateClientFromConnectionString(notificationHubConnection, notificationHubName); 

     // Sending the message so that all template registrations that contain "messageParam" 
     // will receive the notifications. This includes APNS, GCM, WNS, and MPNS template registrations. 
     Dictionary<string, string> templateParams = new Dictionary<string, string>(); 
     templateParams["messageParam"] = "some message"; 

     try 
     { 
      var result = hub.SendTemplateNotificationAsync(templateParams); 
     } 
     catch (System.Exception ex) 
     { 
      config.Services.GetTraceWriter() 
       .Error(ex.Message, null, "Push.SendAsync Error"); 
     } 

结果说,“成功发送:0,发送失败:0

什么可以这个麻烦的原因

更新

我不认为当我尝试通过天蓝色发送通知时发送证书或供应配置文件的问题。 (尽管我没有收到,但这已经是另一个问题)。 enter image description here

更新2

我也努力传递给注册标记,

string payload = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}"; 
List<string> tags = new List<string> {"testTag"}; 
hub.CreateAppleTemplateRegistrationAsync(token,payload,tags); 

Dictionary<string, string> templateParams = new Dictionary<string, string>(); 
      templateParams["messageParam"] = "message"; 
var res = hub.SendTemplateNotificationAsync(templateParams, tags); 

和苹果原生的通知,但结果是一样的。

hub.SendAppleNativeNotificationAsync(payload); 

顺便说一句,notificationId是空的,状态通知显示为'入队'。

+0

您是否验证了您正在使用“监听,管理,发送”连接字符串(来自Azure)进行notificationHubConnection? – mpwhitt

+0

是的,我正在使用FullSharedAccessSignature进行连接 –

+0

您确定您正在为您的应用程序使用正确的配置文件吗?如果不是什么都不会收到。 – Cheesebaron

回答

0

我最终从头开始学习教程,重新创建证书,配置文件,通知集线器等,现在它可以工作。