Flutter插件onairos的特性和使用方法

Flutter插件onairos的特性和使用方法

Flutter插件onairos特性

  • 使用深度链接打开自定义覆盖层。
  • 在覆盖层中传递请求数据和返回链接。
  • 自定义按钮,带有Onairos徽标。

Flutter插件onairos开始使用

要使用Onairos插件,将其包含在你的pubspec.yaml文件中:

dependencies:
  onairos: ^0.1.0

iOS集成

为了处理iOS上的生物识别密钥存储访问(必要)和其他功能,你需要在Info.plist文件中添加以下配置:

第一步配置

<key>NSFaceIDUsageDescription</key>
<string>Authenticate to access secure storage</string>
<key>NSBiometryUsageDescription</key>
<string>This app requires access to your biometric information for authentication purposes.</string>
<key>keychain-access-groups</key>
<array>
  <string>$(AppIdentifierPrefix)com.example.yourappbundleid</string>
</array>

第二步

启用安全区域访问:

在你的应用的目标设置中,在“签名与能力”标签下添加“安全区域”能力。

然后添加以下深度链接权限:

配置您的应用程序以支持深度链接

iOS配置

  1. 更新Info.plist:

    为了处理深度链接,你必须在Info.plist文件下的CFBundleURLTypes中声明你的URL方案。以下是添加自定义URL方案的方法:

    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>onairos</string>
    </array>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>your-custom-scheme</string>
            </array>
        </dict>
    </array>
    

    这种配置允许iOS将具有your-custom-scheme的URL定向到你的应用。

  2. 处理传入的URL:

    在你的AppDelegate中实现application(_:open:options:)方法:

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return true
    }
    

Android配置

  1. 更新AndroidManifest.xml:

    在你的AndroidManifest.xml文件中的<intent-filter>内声明你的URL方案:

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="your-custom-scheme" />
        </intent-filter>
    </activity>
    

    这种配置将具有your-custom-scheme的URL定向到你的应用。

  2. 在Activity中处理Intent:

    在你的onCreateonNewIntent方法中管理Intent:

    [@Override](/user/Override)
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        // 处理Intent以提取数据
    }
    

测试你的配置

  • iOS: 使用Xcode或Safari测试你的URL方案,通过在地址栏输入它来验证。

  • Android: 使用ADB测试你的URL方案:

    adb shell am start -W -a android.intent.action.VIEW -d "your-custom-scheme://test" com.example.yourapp
    

确保你的项目中包含以下AppDelegate.swift文件:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

使用

接下来我们开始添加Onairos集成:

输入参数

  • requestData (Object): 显示给用户的数据,你想访问的用户数据。
  • returnLink (String): 你的应用注册的CFBundleURL,以便onairos应用在首次授权后可以重定向回来。
  • logoAssetPath (String): 显示请求访问时的徽标路径。

这是一个简单的示例,展示如何在你的应用中使用OnairosButton小部件:

import 'package:flutter/material.dart';
import 'package:onairos/onairos.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          // 使用OnairosButton小部件
          child: OnairosButton(
            requestData: {
              'type': 'Personality',
              'descriptions': 'Find out Your Anime Interests',
              'reward': "\$0.30 - Test Money",
            },
            returnLink: 'yourapp://returnlink',
            logoAssetPath: 'onairos_logo.png',
          ),
        ),
      ),
    );
  }
}

更多关于Flutter插件onairos的特性和使用方法的实战教程也可以访问 https://www.itying.com/category-92-b0.html

回到顶部