iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 21
1
Cloud

Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例系列 第 21

Day21 - Azure Mobile App & Azure Notification Hubs Part4 整合ASP.NET CORE WEB API篇

終於來到這個系列的最後一篇, 主要是實作如何透過ASP.NET CORE對不同的行動裝置如IOS或Android同時發Push Message, 但是要開始實作前遇到了個難題, 因為想要透過ASP.NET CORE發訊息, 需要參照Microsoft.Azure.NotificationHubs, 但是現階段不支援ASP.NET CORE 1.1的版本, 據說日後會支援, 所以只好把專案類型切回去.NET Framework 4.6, 這樣做的優點是支援所有.NET Namesapce, 缺點就是不能跨平台了, 只能跑在Windows上了, 切換方式就是找到project.json, 修改如下
http://ithelp.ithome.com.tw/upload/images/20170102/20103333W8d4F2ctQb.png
http://ithelp.ithome.com.tw/upload/images/20170102/20103333UklVLoXVys.png

接著新增一個NotificationPush的View如下紅框所示
http://ithelp.ithome.com.tw/upload/images/20170102/20103333h3PPqQyztW.png

接著到AppController.cs加入Microsoft.Azure.NotificationHubs Namespace
http://ithelp.ithome.com.tw/upload/images/20170102/20103333Zqytvt4GyG.png

加入NotificationPush函式, 回傳預設的View
http://ithelp.ithome.com.tw/upload/images/20170102/20103333DZYfViHBNG.png

再加入NotificationPush函式, 並宣告HttpPost接收前端表單回傳的字串
http://ithelp.ithome.com.tw/upload/images/20170102/20103333m8S2xgu0Qp.png

底下這兩個宣告, 可以到Azure Portal Notificationservices找到如下紅框所示
private string notificationHubName
http://ithelp.ithome.com.tw/upload/images/20170102/201033337fTSfqoplJ.png

private string notificationHubConnection
http://ithelp.ithome.com.tw/upload/images/20170102/20103333yiCrXHEB1n.png

接著把站台跑起來測試
http://ithelp.ithome.com.tw/upload/images/20170102/201033332ZV9OSzTEf.png

按下Send, 成功畫面如下
http://ithelp.ithome.com.tw/upload/images/20170102/20103333RJzHu7ueCd.png

接著就可以在IOS跟Android看到囉
IOS
http://ithelp.ithome.com.tw/upload/images/20170102/20103333iI9gI2yyp1.png

Android
http://ithelp.ithome.com.tw/upload/images/20170102/20103333Nzn6QGc6bE.png

本系列文參照底下URL
https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push
https://developer.xamarin.com/guides/xamarin-forms/web-services/push-notifications/azure/

後記: 終於寫完了/images/emoticon/emoticon34.gif, 這個算是第一個將Xamarin Forms, Azure與ASP.NET CORE WEB API的整合應用.


上一篇
Day20 - Azure Mobile App & Azure Notification Hubs Part3 IOS篇
下一篇
Day22 - Azure App Service & Azure SQL Database Part1 Entity Framework Core本地開發篇
系列文
Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言