Let’s try new iOS 12 Security Code AutoFill feature in Xamarin.Forms!
The new iOS 12 update has brought a whole bunch of awesome updates, although which were mostly already was available on Android years back.
One of those features is getting rid of the old annoying OTP code filling process in iOS apps, where as every time you have to insert an OTP code into the app you have to quit the app and go to the messages and copy and past the OTP manually into the app.
But with iOS 12 update they have made it easier by allowing Apps to auto read OTP messages without going back and forth into the Message app or copy and pasting. iOS now automatically suggest the top most available OTP message in the inbox for your OTP Text fields in the Keyboard suggestion bar.
Well its not practically auto-read but still much convenient than before 😉 lol
What happens is that when an OTP message receives into the Message Inbox, iOS runs a simple text matching algorithm that determines if that message is a valid OTP message or not and based on that keep a track of it in the memory, then when the user clicks on the OTP AutoFill enabled text field in an app, iOS keyboard popup that OTP as a suggestion in the keyboard. So that your users can fill up the OTP into the app without leaving the app or going back into the Messaging app. Pretty convenient!
iOS 12 update in Xamarin!
Following the new iOS 12 update, Xamarin has immediately released the support for it within weeks, so make sure to update your XCode and Xamarin nuget packs, to get your hands dirty with it!
Let’s try it in Xamarin.Forms!
Since iOS 12 is now fully supported on Xamarin, we can access those features in our Xamarin.Forms projects as well, by accessing the Xamarin native project levels. So before we get started please make sure you have updated your Xamarin iOS packages.
iOS provides a new property called UITextContentType.OneTimeCode for the TextContentType property of UITextField in Xamarin.
We’re gonna do this using a custom renderer allowing us to access the UITextField’s native properties, which is the native counterpart of Xamarin.Forms.Entry in iOS.
So let’s start by creating the Custom Control: OTPAutoFillControl
Then’ let’s createthe Custom Renderer!
There we go, setting up our Xamarin.Forms.Entry’s native counterpart UITextField for the OTP Auto-Fill feature in iOS 12.
Alright that’s it you’re all good to go.
Now use our OTPAutoFillControl anywhere in your Xamarin.Forms app, deploy to an iOS 12 Device, then retrieve an OTP message, and see the magic happens! 😉
How simple eh! 😀 yep even I was surprised at first.
Check out my github repo sample:
iOS still doesn’t give out much awesome features or god-mode control of the device, but still this by far a really nice and easy to use feature from a developer’s perspective!
Few things to keep in mind!
First thing, iOS 12 – OTP Auto-Fill feature works perfectly in Xamarin Native and Xamarin.Forms because of the native magic of Xamarin. You have nothing to worry!
Then keep in mind, there’s a certain pattern of OTP messages iOS 12 supports for now, not to worry, its mostly standard ones such as below,
(Source: Apple Dev Conference WWDC 2018)
So please do keep an eye out for the OTP message structure if you run into any issues using this feature, otherwise it should work right out of the box like a charm! 😀
Now if you like to learn more about the iOS 12 developer’s update, check out their WWDC 2018 conference:
or wanna learn more of the new OTP AutoFill or Password generate in native iOS, check out these gems:
There you go!
Spread the love! 😀