How to populate OTP from user's message box to application directly in iPhone? [duplicate]
Asked Answered
L

3

6

I am working on an internet trading application with its mobile and iPhone applications available. With the recent market trend, we are working on including two-factor authentication. For that, we will be sending a one-time password as a sms on user's registered mobile number.

Is there a way,that the OTP can get automatically populated into application from user's message box in iPhone? What algorithm should I use to make my app read user's message box?

Thanks in advance:)

Lump answered 3/1, 2014 at 10:46 Comment(6)
That question does not contain a valid and useful answer.Lump
valid and useful in terms of what ? it is not possible to read sms programmatically is confirmed. Other way you can look forward is suggested by @rckoenesLacewing
Possible answers on the site suggests jail-breaking the ios first. Jail-breaking an iPhone is like a privilege escalation that my client may or may not do. i cant ask my client to mandatorily Jailbreak his phone in order for my App to work smoothly on it.Lump
So for that we have jailbreak tag here on SO, and also you can specify in your question that you are open to the possibilities on jailbreak as well. And I suggested possible duplicate not duplicate.Lacewing
All right yes, agreed, but i just wanted to tell you that i am looking for more feasible options then suggested in the possible duplicate. Also, I did not use the jailbreak tag, neither did I use the term, so I would like add upon, I am not open to playing with the end client's phone. I hope i am clear now.Lump
May I know how to send OTP from mobile to particular mobile number as SMS.Gastrocnemius
G
3

You can Access SMS from your app. So better make user to enter his contact number and send SMS to his mobile

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if (!url) {
        UIApplication * yourapplication =[UIApplication sharedApplication];
        NSString *outputpath =@"appname://data/";
        NSURL *url =[NSURL URLWithString:outputpath];
        [yourapplication openURL:url];
        return NO;
    }

    NSUserDefaults *defaultString =[NSUserDefaults standardUserDefaults];
    NSString * commonString =[url absoluteString];
    if (commonString.length<=15) {
        //
    }
    else
    {
        [defaultString setObject:commonString forKey:@"urlString"];
    }
         //send info to the screen you need and can navigate
    return YES;
}
Geary answered 3/1, 2014 at 10:55 Comment(13)
LoadLog (free app) I developed that application where the total information will be sent through SMS only. No server is used for that applicationGeary
User is already receiving a sms on his mobile, but I want to ease out the process for him. The OTP should automatically get populated as the user receives it as a sms.Lump
@Lump that is what i said OTP will be send to SMS only(the only and best possible way for mobiles) and you can access them. are you expecting something other than SMS?Geary
Yes, I am looking forward to a possiblity, where-in , if the user is using app on the same phone on which the sms arrives, app should be capable of automatically reading the OTP from that sms and put it directly on the app. This is to reduce the user's work of minimizing the app, reading the sms and then goin back to app to enter the OTP.Lump
This can be done. I used same in LoadLog app, but SMS will be sent by Admin.Geary
okay, then here I am the admin, I'll be sending the sms to user, now my App should be capable of reading that sms. HOW to do it is the question.Lump
i'll send code for itGeary
yea..ty ..looking forward to it :)Lump
In Plist you need to add <Key>CFBundleURLTypes</Key> <array><dict><Key>CFBundleURLName</key><string>yourbundleidentifier</string><Key>CFBundleURLSchemes</Key><array>yourappname</array></dict></array>Geary
your SMS should be like "appname://data/OTP" ex: appname://data/1234Geary
@CharanGiri Im also need same type of behaviour, Im sending a phone number to my web service, and they are sending the OTP msg like "Your requested OTP is 123 and valid till ......." So Now how can i read it from My app. Could u plz explain me with some steps..Connel
@sivakrishna just send the OTP message as appname://OTP-valid till time/ as SMS... once you receive the message just click on the SMS it will redirect to your application. Now important part is you need to validate/ write some piece of code to split the OTP and valid till timestamp. once you split it you are ready to use OTP. In the above code try to see what is there in "commonString" for you, from here your logic of splitting startsGeary
@CharanGiri Thanks for reply, But I hope it is not the correct way, Until and unless user clicked on SMS we are unable to get OTP. I think There should be another way like "whatsApp" did. Let me know if any procedure..Connel
L
8

Straight Forward answer NO

It is not possible to read SMS programmatically as of now as applications in iOS are sandboxed, which means you can not read anything from user's phone outside of your application.

Lacewing answered 3/1, 2014 at 10:49 Comment(0)
M
8

You can not access to the users SMS inbox, this would be a real privacy issue.

What you can do is register your own app schema, with your app can be opened. The you can do something like myApp://register/<OTP>, you can then pick up this URL and take the OTP from the URL and use it. Just use the URL in your SMS and iOS will do the rest.

You can parse the app URL in - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation in your app delegate.

Martinamartindale answered 3/1, 2014 at 10:50 Comment(6)
Thank you, but as i learned from another comment, inbox are sandboxed, will it create a trouble?Lump
And also, does this work in android phones?Lump
No this will not create any trouble and yes you can use the same app URL on android.Martinamartindale
Thanks a lot, I'll test it and get back on the forum.Lump
Hi, there was this 1 confusion. I am already sending sms to the user for OTP, where should I place myApp://register/<OTP> in my code? And what changes will i have to make in iPhone/Android code in order to make it accept the OTP directly from the sms without user manually entering it.Lump
hi @Lump i am developing an application where on registering in app it sends an otp.Can you please help me in doing thisCircumlunar
G
3

You can Access SMS from your app. So better make user to enter his contact number and send SMS to his mobile

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if (!url) {
        UIApplication * yourapplication =[UIApplication sharedApplication];
        NSString *outputpath =@"appname://data/";
        NSURL *url =[NSURL URLWithString:outputpath];
        [yourapplication openURL:url];
        return NO;
    }

    NSUserDefaults *defaultString =[NSUserDefaults standardUserDefaults];
    NSString * commonString =[url absoluteString];
    if (commonString.length<=15) {
        //
    }
    else
    {
        [defaultString setObject:commonString forKey:@"urlString"];
    }
         //send info to the screen you need and can navigate
    return YES;
}
Geary answered 3/1, 2014 at 10:55 Comment(13)
LoadLog (free app) I developed that application where the total information will be sent through SMS only. No server is used for that applicationGeary
User is already receiving a sms on his mobile, but I want to ease out the process for him. The OTP should automatically get populated as the user receives it as a sms.Lump
@Lump that is what i said OTP will be send to SMS only(the only and best possible way for mobiles) and you can access them. are you expecting something other than SMS?Geary
Yes, I am looking forward to a possiblity, where-in , if the user is using app on the same phone on which the sms arrives, app should be capable of automatically reading the OTP from that sms and put it directly on the app. This is to reduce the user's work of minimizing the app, reading the sms and then goin back to app to enter the OTP.Lump
This can be done. I used same in LoadLog app, but SMS will be sent by Admin.Geary
okay, then here I am the admin, I'll be sending the sms to user, now my App should be capable of reading that sms. HOW to do it is the question.Lump
i'll send code for itGeary
yea..ty ..looking forward to it :)Lump
In Plist you need to add <Key>CFBundleURLTypes</Key> <array><dict><Key>CFBundleURLName</key><string>yourbundleidentifier</string><Key>CFBundleURLSchemes</Key><array>yourappname</array></dict></array>Geary
your SMS should be like "appname://data/OTP" ex: appname://data/1234Geary
@CharanGiri Im also need same type of behaviour, Im sending a phone number to my web service, and they are sending the OTP msg like "Your requested OTP is 123 and valid till ......." So Now how can i read it from My app. Could u plz explain me with some steps..Connel
@sivakrishna just send the OTP message as appname://OTP-valid till time/ as SMS... once you receive the message just click on the SMS it will redirect to your application. Now important part is you need to validate/ write some piece of code to split the OTP and valid till timestamp. once you split it you are ready to use OTP. In the above code try to see what is there in "commonString" for you, from here your logic of splitting startsGeary
@CharanGiri Thanks for reply, But I hope it is not the correct way, Until and unless user clicked on SMS we are unable to get OTP. I think There should be another way like "whatsApp" did. Let me know if any procedure..Connel

© 2022 - 2024 — McMap. All rights reserved.