MAUIでiOSアプリの開発!

MAUIを使ったiOSアプリの開発についての技術的なメモです。

WebAPIを使うiOSアプリで通信のテストをする場合

サーバ(Windows)とWebAPIで通信を行うiOSアプリを開発しています。

テスト用にWindowsASP.NETのWebAPI2のアプリを立ち上げて、Mac上のiOSシミュレータのアプリからWebAPI(https)通信を行ってみました。

 

結果、HttpClientのメソッドを呼び出したところで例外が発生しました。

    The certificate for this server is invalid. You might be connecting to a server that is pretending to be “xxx.xxx.xxx.xxx” which could put your confidential information at risk.

調べたところ、iOSアプリからなんちゃって証明書を使ったhttpsのサイトにはアクセスできないようです。
回避策として、http通信を行えるよう設定できました。
info.plistに以下の設定を追加します。

	
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
</dict>

これでhttpならアクセスできましたので、テストを続けます。

以下のサイトに、これら設定方法や、httpsで通信できるように証明書の設定方法等ありました。

Certificate Pinning in iOS Application with Xamarin