1. 簡單說明
專案使用到了CocoaAsyncSocket,建立TCP之前,使用了UDP廣播獲取IP地址,但是系統升級到iOS 14之后,發現有臺iPad間歇性可以收到廣播,iPhone一直沒有收到廣播,
2. 解決辦法
-
Info.plist添加NSLocalNetworkUsageDescription
-
到這個頁面申請APP接受組播或廣播的權限Multicast Networking Entitlement Request
如果打開報502,可以嘗試復制鏈接到Safari打開重試,
打開后頁面會有下面說明,主要是填寫App資訊并解釋一下用到UDP組播或廣播的目的,
// 說明 Multicast Networking Entitlement Request This entitlement allows advanced networking apps to interact with their local network by sending multicast and broadcast IP packets and browsing for arbitrary Bonjour service types. Your app may need to access this level of networking in order to communicate with custom or non-standard devices or to act as a network utility. If your app needs this entitlement to function properly on iOS 14 or later, provide the following information. // 開發賬號資訊 Developer Information // App 資訊 App Information ...... Explain why your app needs to send multicast or broadcast traffic, or browse for all Bonjour service types.
-
如果你的APP需要發送UDP廣播,需要先發送一個偽包來觸發彈框(本地網路訪問),讓用戶確定后,再開始發送UDP廣播,如果只是接受廣播,不用處理,
-
填寫完點擊發送,
Thank you for your submission. We will review your request and will get back to you.
3. 參考原文內容
First things first, make sure you populate NSLocalNetworkUsageDescription in your Info.plist.
Next, make sure to apply for and, once it’s granted, enable the com.apple.developer.networking.multicast. iOS 14 will eventually require this for anyone doing multicasts and broadcasts (currently this requirement is not enforced for BSD Sockets clients).
Finally, be aware that the local network privacy alert is only triggered when you send traffic, so if your UDP socket only receives and never sends then you won’t see the alert. The current workaround is to send a dummy packet to trigger the alert.
看下官方說明
// A Boolean value that indicates whether an app can send or receive IP multicast traffic.
com.apple.developer.networking.multicast
/* Discussion
Your app must have this entitlement to send or receive IP multicast or broadcast on iOS. It also allows your app to browse and advertise arbitrary Bonjour service types.
This entitlement requires permission from Apple before you can use it in your app. Request permission from the Multicast Networking Entitlement Request page.
*/
4. 參考鏈接
https://developer.apple.com/forums/thread/662082
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/138843.html
標籤:其他
上一篇:基礎篇:深入決議JAVA反射機制
