简体   繁体   English

使用Firebase在ios中推送通知

[英]push notification in ios using firebase

How can I use push notification capabilities in my project? 如何在项目中使用推送通知功能? I don't have developer account, I tried this code 我没有开发者帐户,我尝试过此代码

@IBAction func PhoneSignIn(_ sender: Any) {
    let alert = UIAlertController(title: "Phone number", message: "Is this your phone number? \n \(PhoneOu.text!)", preferredStyle: .alert)
    let action = UIAlertAction(title: "Yes", style: .default) { (UIAlertAction) in
        PhoneAuthProvider.provider().verifyPhoneNumber(self.PhoneOu.text!, uiDelegate: nil) { (verificationID, error) in
            if error != nil {
                print("eror: \(String(describing: error?.localizedDescription))")
            } else {
                let defaults = UserDefaults.standard
                defaults.set(verificationID, forKey: "authVID")
                self.performSegue(withIdentifier: "code", sender: Any?.self)
            }
        }
    }
    let cancel = UIAlertAction(title: "No", style: .cancel, handler: nil)
    alert.addAction(action)
    alert.addAction(cancel)
    self.present(alert, animated: true, completion: nil)
}

When you call verifyPhoneNumber:UIDelegate:completion:, Firebase sends a silent push notification to your app, or issues a reCAPTCHA challenge to the user . 当您调用verifyPhoneNumber:UIDelegate:completion:时, Firebase会向您的应用发送静默推送通知,或向用户发出reCAPTCHA质询 After your app receives the notification or the user completes the reCAPTCHA challenge, Firebase sends an SMS message containing an authentication code to the specified phone number and passes a verification ID to your completion function. 在您的应用收到通知或用户完成reCAPTCHA挑战后,Firebase将包含验证码的SMS消息发送到指定的电话号码,并将验证ID传递给您的完成功能。 You will need both the verification code and the verification ID to sign in the user. 您将需要验证码和验证ID来登录用户。

If you don't have a developer account, this is currently not possible using push notifications, better use reCAPTCHA : 如果您没有开发者帐户,则当前无法使用推送通知来实现,最好使用reCAPTCHA

Set up reCAPTCHA verification: 设置reCAPTCHA验证:

To enable the Firebase SDK to use reCAPTCHA verification: 要使Firebase SDK能够使用reCAPTCHA验证,请执行以下操作:

Add custom URL schemes to your Xcode project: 将自定义URL方案添加到您的Xcode项目:

a. 一种。 Open your project configuration: double-click the project name in the left tree view. 打开项目配置:在左树视图中双击项目名称。 Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section. 从“目标”部分中选择您的应用,然后选择“信息”选项卡,然后展开“ URL类型”部分。

b. b。 Click the + button, and add a URL scheme for your reversed client ID. 单击+按钮,然后为您的反向客户端ID添加URL方案。 To find this value, open the [![GoogleService-Info.plist][1]][1] configuration file, and look for the REVERSED_CLIENT_ID key. 要找到此值,请打开[![GoogleService-Info.plist][1]][1]配置文件,然后寻找REVERSED_CLIENT_ID密钥。 Copy the value of that key, and paste it into the URL Schemes box on the configuration page. 复制该键的值,然后将其粘贴到配置页上的“ URL方案”框中。 Leave the other fields blank. 将其他字段留空。 When completed, your config should look something similar to the following (but with your application-specific values): 完成后,您的配置应类似于以下内容(但具有特定于应用程序的值):

img

  1. Optional : If you want to customize the way your app presents the SFSafariViewController or UIWebView when displaying the reCAPTCHA to the user, create a custom class that conforms to the FIRAuthUIDelegate protocol, and pass it to verifyPhoneNumber:UIDelegate:completion: . 可选 :如果要自定义应用程序在向用户显示reCAPTCHA时呈现SFSafariViewController或UIWebView的方式,请创建一个符合FIRAuthUIDelegate协议的自定义类,并将其传递给verifyPhoneNumber:UIDelegate:completion:

Read more: 阅读更多:

Authenticate with Firebase on iOS using a Phone Number 使用电话号码在iOS上通过Firebase进行身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM