Erlo

iOS 14 UDP收不到广播处理

2020-09-29 14:30:28 发布   1339 浏览  
页面报错/反馈
收藏 点赞

1. 简单说明

项目使用到了CocoaAsyncSocket,建立TCP之前,使用了UDP广播获取IP地址,但是系统升级到iOS 14之后,发现有台iPad间歇性可以收到广播,iPhone一直没有收到广播。

2. 解决办法

  1. Info.plist添加NSLocalNetworkUsageDescription

  2. 到这个页面申请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.
    

  1. 如果你的APP需要发送UDP广播,需要先发送一个伪包来触发弹框(本地网络访问),让用户确定后,再开始发送UDP广播。如果只是接受广播,不用处理。

  2. 填写完点击发送。

    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

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认