Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET MVC Azure应用程序iOS推送通知_Ios_Asp.net Mvc_Azure_Apple Push Notifications_Pushsharp - Fatal编程技术网

ASP.NET MVC Azure应用程序iOS推送通知

ASP.NET MVC Azure应用程序iOS推送通知,ios,asp.net-mvc,azure,apple-push-notifications,pushsharp,Ios,Asp.net Mvc,Azure,Apple Push Notifications,Pushsharp,我正试图找出处理这种情况的最佳方法 我在Azure中有一个MVC后端,它为我的应用程序提供了一系列端点。我想添加另一个端点来处理向用户发送iOS推送通知 我正在处理存储他们的设备令牌,所以我的想法是只使用PushSharp并在每个令牌上循环,然后将适当的令牌推给用户。这在本地非常有效,但我似乎无法让PushSharp在Azure中工作。我在这里看到了这个解决方案: 但是,我不确定什么是ServiceDefinition.csdef文件,以及如何将其整合到我的MVC解决方案中 我已经开始研究Az

我正试图找出处理这种情况的最佳方法

我在Azure中有一个MVC后端,它为我的应用程序提供了一系列端点。我想添加另一个端点来处理向用户发送iOS推送通知

我正在处理存储他们的设备令牌,所以我的想法是只使用PushSharp并在每个令牌上循环,然后将适当的令牌推给用户。这在本地非常有效,但我似乎无法让PushSharp在Azure中工作。我在这里看到了这个解决方案:

但是,我不确定什么是
ServiceDefinition.csdef
文件,以及如何将其整合到我的MVC解决方案中


我已经开始研究Azure通知中心,但我不确定它是否能满足我的需要。我只是在寻找一个简单的C#解决方案,它可以托管在Azure(ASP.NET MVC)中,在那里我可以循环一组设备令牌和推送通知。

如果您已经有Azure托管的MVC应用程序,它可以从最终用户的iOS应用程序获取和存储设备令牌,然后,您可以在其中创建服务总线名称空间和通知中心,上载APNS证书,然后您的MVC应用程序就可以使用注册令牌和发送通知

下面是非常基本的代码示例:

 var notificationHubClint = NotificationHubClient.CreateClientFromConnectionString("{connection string from the portal}", "{your hub name}");

 // Register device token with notification hub. Call it when you get device token from iOS app first time.
 var registration = await notificationHubClint.CreateAppleNativeRegistrationAsync("{device token}",new []{"SomeUserId"});

 // You can modify properties or refresh device token and then update registration
 registration.DeviceToken = "{new token}";
 registration.Tags.Add("{new tag}");
 await notificationHubClint.UpdateRegistrationAsync(registration);

 // Send notification. Call when you want to send notification to user.
 await notificationHubClint.SendAppleNativeNotificationAsync("{your message}","some user id");

在这里,我使用标记来定位特定用户的消息。若您只调用sendappletivenotificationasync(“{yourmessage}”),那个么消息将传递给所有用户。学习如何提高发送效率。

如果您已经拥有Azure托管的MVC应用程序,该应用程序从最终用户iOS应用程序获取并存储设备令牌,那么您可以在其中创建服务总线命名空间和通知中心,上载APNS证书,然后,您的MVC应用程序可以使用注册令牌和发送通知

下面是非常基本的代码示例:

 var notificationHubClint = NotificationHubClient.CreateClientFromConnectionString("{connection string from the portal}", "{your hub name}");

 // Register device token with notification hub. Call it when you get device token from iOS app first time.
 var registration = await notificationHubClint.CreateAppleNativeRegistrationAsync("{device token}",new []{"SomeUserId"});

 // You can modify properties or refresh device token and then update registration
 registration.DeviceToken = "{new token}";
 registration.Tags.Add("{new tag}");
 await notificationHubClint.UpdateRegistrationAsync(registration);

 // Send notification. Call when you want to send notification to user.
 await notificationHubClint.SendAppleNativeNotificationAsync("{your message}","some user id");

在这里,我使用标记来定位特定用户的消息。若您只调用sendappletivenotificationasync(“{yourmessage}”),那个么消息将传递给所有用户。学习如何提高发送效率。

您好,谢谢。是否有此示例代码?我似乎不知道如何将设备令牌与ServiceBus DLL一起使用。请确保对单个设备只调用一次CreateAppleNativeRegistrationAsync。下次如果你想刷新令牌或添加/删除一些标记等,那么你应该调用UpdateRegistrationAsync。这很奇怪,在更新时,我认为你无法访问注册对象,因为它只应该调用一次,正确吗?nevermind看起来就像您可以启动对象来更新var regs=new applereRegistrationDescription(“token”,new[]{“userid”});hub.UpdateRegistrationAsync(regs);您可以存储注册Id,然后创建AppleRegistrationDescription类的新示例。另外,有些人使用GetRegistrationsByTagAsync(“用户id”,100)或GetRegistrationsByChannelAsync(“设备令牌”,100)只是为了从集线器中检索注册,但事实上,该调用不会对后端和通知集线器本身造成不必要的性能影响。您好,谢谢,有此示例代码吗?我似乎不知道如何将设备令牌与ServiceBus DLL一起使用。请确保对单个设备只调用一次CreateAppleNativeRegistrationAsync。下次如果你想刷新令牌或添加/删除一些标记等,那么你应该调用UpdateRegistrationAsync。这很奇怪,在更新时,我认为你无法访问注册对象,因为它只应该调用一次,正确吗?nevermind看起来就像您可以启动对象来更新var regs=new applereRegistrationDescription(“token”,new[]{“userid”});hub.UpdateRegistrationAsync(regs);您可以存储注册Id,然后创建AppleRegistrationDescription类的新示例。另外,有些人使用GetRegistrationsByTagAsync(“用户id”,100)或GetRegistrationsByChannelAsync(“设备令牌”,100)只是为了从集线器检索注册,但事实上,该调用对后端和通知集线器本身造成了不必要的性能影响。