diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index 282b66d9b..c6b22d63e 100755 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -3,6 +3,7 @@ @interface FirebasePlugin : CDVPlugin + (FirebasePlugin *) firebasePlugin; +- (void)getVerificationID:(CDVInvokedUrlCommand*)command; - (void)getInstanceId:(CDVInvokedUrlCommand*)command; - (void)getId:(CDVInvokedUrlCommand*)command; - (void)getToken:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 7f0a72dea..be816aebb 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -8,6 +8,7 @@ @import FirebaseRemoteConfig; @import FirebasePerformance; @import FirebaseCrash; +@import FirebaseAuth; #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 @import UserNotifications; @@ -154,6 +155,37 @@ - (void)grantPermission:(CDVInvokedUrlCommand *)command { ]; return; +} + +- (void)getVerificationID:(CDVInvokedUrlCommand *)command { + NSString* number = [command.arguments objectAtIndex:0]; + + [[FIRPhoneAuthProvider provider] + verifyPhoneNumber:number + completion:^(NSString *_Nullable verificationID, + NSError *_Nullable error) { +NSDictionary *message; + if (error) { + + // Verification code not sent. + message = @{ + @"code": [NSNumber numberWithInteger:error.code], + @"description": error.description == nil ? [NSNull null] : error.description + }; + + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:message]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + + } else { + // Successful. +CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:verificationID]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } +}]; + + + } - (void)setBadgeNumber:(CDVInvokedUrlCommand *)command { diff --git a/www/firebase-browser.js b/www/firebase-browser.js index 124ed21a6..9aaca6b28 100755 --- a/www/firebase-browser.js +++ b/www/firebase-browser.js @@ -4,6 +4,12 @@ exports.getVerificationID = function (number, success, error) { } }; +exports.getVerificationID = function (number, success, error) { + if (typeof success === 'function') { + success(); + } +}; + exports.getInstanceId = function (success, error) { if (typeof success === 'function') { success(); diff --git a/www/firebase.js b/www/firebase.js index fe727b8a3..cb9a10f8d 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -1,5 +1,9 @@ var exec = require('cordova/exec'); +exports.getVerificationID = function (number, success, error) { + exec(success, error, "FirebasePlugin", "getVerificationID", [number]); +}; + exports.getInstanceId = function (success, error) { exec(success, error, "FirebasePlugin", "getInstanceId", []); };