I was sitting on the autobahn, shoe horned into my mother-in-laws little Audi, trying to pair my iPhone 7 plus to the magic keyboard but having no luck - sound familiar - well the pairing part that is?
I first checked to see if Apple even allows BT keyboards to connect to IOS, they never used to but this article https://support.apple.com/en-us/HT202041 said "all devices after iOS 9.1" so that wasn't the issue - thanks Apple we can now actually use a BT keyboard with our iPhones. Next I tried to turn off and on the keyboard and phone's bluetooth connection - no deal! A couple on minutes later I was thrust an iPhone 6S plus from the back seat and asked to fix Nextlix. We'd been using the "offline video" feature but I was unable to connect to any offline videos and Nexflix simple presented a spinning wheel icon as if it were trying to download the video over the internet. I simply put the iPhone in airplane mode and the video immediately started playing. I then went back to my pairing issue and after turning the BT on and off on my iPhone the naughty keyboard connected perfectly in seconds. Of course, I'd had this problem many times before I recalled trying to connect the BT keyboard to an Apple TV as well as a BT mouse a few years ago. This issue is if you have several IOS device with BT turned on in close proximity it seems to mess with the pairing process . Simply turning off the BT connect of the iPhone behind me fixed the issue. There was also an iPad behind me and on checking it was observed to be airplane mode.
So there you gave it, bluetooth paring woes - make sure other IOS (and perhaps laptops / OSX) devices nearby are not messing with the bluetooth pairing process.