is there any way to change the MTU value on iOS from the default to an arbitrary value?

Much like in Android it's possible to do requestMTU(512).

Thanks

2

Best Answer


No, MTU on iOS is set automatically, maximum value is 185. This is a good answer to your question: https://stackoverflow.com/a/42336001/10380092

Note: you can get MTU value this way (it will be 3 bytes less than the ATT MTU):

connectedPeripheral.maximumWriteValueLength(for: .withoutResponse)

It's important to use parameter .withoutResponse, because .withResponse will always return 512 (when writing with response, iOS automatically chooses the approach: single write if data is shorter than MTU, or queued write if data is larger than MTU).

this is not an answer but it is interesting non the less. It is a reply from apple engineer on a request I send on the problem.

Hi,

Yes, the issue you are seeing is indeed due to the timing problem/racecondition I was suspecting. The reason you are getting DPLE and MTUalmost simultanously is, iOS has received the MTU request too early,and as it has not been able to determine if the connection supportsEDL, it responds with the minimum.

In iOS 15 this race condition is being handled differently, and theMTU response is held off until the link is ready. Technically theperipheral is not doing something wrong, as the spec allows the MTUrequest to be sent at any time. Just that on iOS 14, on differentdevices, this issue may pop-up.

I can’t tell you to not send the MTU request at that time, becausespec allows it. And iOS 15 is handling it in a way to bypass theseissues.

Delaying the MTU request until PHY update may make the problem lesslikely, but there is no guarantee that it will not happen ever. Theroot issue here is that HCI events like PHY Update or EDL change areissued by each controller locally and there is no way to guaranteethat just because your peripheral reports EDL that the iPhonecontroller has also done so. And unfortunately this timing/race issuewill be different from controller to controller, therefore from phoneto phone.

So I hope it helps.The BLE peripheral we are developing is sending all the commands for the connection negotiation pretty much all at the same time. And this is what was causing us to not be able to get the data length extension.