Places 扩展

Places扩展允许您根据用户的位置执行操作。 此扩展是Places查询服务API的接口。 通过侦听包含GPS坐标和地理围栏区域事件的事件,此扩展将调度由规则引擎处理的新事件。 Places扩展还会检索并提供从API检索的应用程序数据所对应的最近POI的列表。 API返回的区域存储在缓存和持久性中,这允许进行有限的离线处理。

在Adobe Experience Platform Launch中安装Places扩展

  1. 在Experience Platform Launch中,单击 扩展 选项卡。

  2. 目录 ,找到 位置 扩展,然后单击 安装.

  3. 选择要在此资产中使用的Places库。 这些库将在您的应用程序中访问。

  4. 单击​保存

    单击 保存,则Experience PlatformSDK会在Places Services中搜索您选择的库中的POI。 在构建应用程序时,库下载中不包含POI数据,但会在运行时将基于位置的POI子集下载到最终用户的设备,并且该子集基于用户的GPS坐标。

  5. 完成发布过程以更新SDK配置。

    有关在Experience Platform Launch中发布的更多信息,请参阅 发布.

配置Places扩展

将Places扩展添加到您的应用程序

您可以将Places扩展添加到Android和iOS应用程序。 下面显示了向iOS或Android应用程序添加Places的步骤。 Places扩展还可用于以下平台。 有关在使用其中一个平台进行开发时向应用程序添加Places的信息,请参阅随附的链接:

Cordova Places插件

React Native Places插件

颤动位置插件

Xamarin Places插件

Android

要使用Java将Places扩展添加到应用程序,请执行以下操作:

  1. 使用应用程序的Gradle文件将Places扩展添加到您的项目中。

    implementation 'com.adobe.marketing.mobile:places:1.+'
    implementation 'com.adobe.marketing.mobile:sdk-core:1.+'
    
  2. 在应用程序的主活动中导入Places扩展。

    import com.adobe.marketing.mobile.Places;
    

iOS

要使用Objective-C或Swift将Places扩展添加到您的应用程序,请执行以下操作:

  1. 添加位置和 移动核心 库。 您需要将以下Pod添加到 Podfile:

    pod 'ACPPlaces', '~> 1.0'
    pod 'ACPCore', '~> 2.0'    # minimum Core version for Places is 2.0.3
    

    或者,如果您未使用Cocoapods,则可以手动从我们的 版本页 在Github上。

  2. 更新您的Cocoapods:

    pod update
    
  3. 打开Xcode,然后在AppDelegate类中,导入核心和Places标头:

    Objective-C

    #import "ACPCore.h"
    #import "ACPPlaces.h"
    

    Swift

    import ACPCore
    import ACPPlaces
    

在Mobile Core中注册Places扩展

您需要在Android和iOS中在Mobile Core中注册Places扩展。

Android

在您应用程序的 OnCreate 方法注册Places扩展:

public class PlacesTestApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        MobileCore.setApplication(this);

        try {
            Places.registerExtension();
            MobileCore.start(null);
        } catch (Exception e) {
            Log.e("PlacesTestApp", e.getMessage());
        }
    }
}

iOS

在您应用程序的 application:didFinishLaunchingWithOptions: 方法中,在您的其他SDK注册调用中注册Places扩展:

Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // make other sdk registration calls
    [ACPPlaces registerExtension];
    return YES;
}

Swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // make other sdk registration calls
    ACPPlaces.registerExtension();
    return true;
}

修改Places成员资格的生存时间

位置数据可能会很快失效,特别是当设备未收到后台位置更新时。

通过设置 places.membershipttl 配置设置。 传入的值表示Places状态对设备保持有效的秒数。

Android

在的回调中 MobileCore.start() 在调用 lifecycleStart:

public class PlacesTestApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        MobileCore.setApplication(this);

        try {
            Places.registerExtension();
            MobileCore.start(new AdobeCallback() {
                @Override
                public void call(Object o) {
                    // switch to your App ID from Launch
                    MobileCore.configureWithAppID("my-app-id");

                    final Map<String, Object> config = new HashMap<>();
                    config.put("places.membershipttl", 30);
                    MobileCore.updateConfiguration(config);

                    MobileCore.lifecycleStart(null);
                }
            });
        } catch (Exception e) {
            Log.e("PlacesTestApp", e.getMessage());
        }
    }
}

iOS

ACPCore's start: 方法,调用 updateConfiguration:

Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // make other sdk registration calls

    const UIApplicationState appState = application.applicationState;
    [ACPCore start:^{
        [ACPCore updateConfiguration:@{@"places.membershipttl":@(30)}];

        if (appState != UIApplicationStateBackground) {
            [ACPCore lifecycleStart:nil];
        }
    }];

    return YES;
}

Swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // make other sdk registration calls

    let appState = application.applicationState;
    ACPCore.start {
        ACPCore.updateConfiguration(["places.membershipttl" : 30])

        if appState != .background {
            ACPCore.lifecycleStart(nil)
        }
    }

    return true;
}

配置键

要在运行时以编程方式更新SDK配置,请使用以下信息更改您的Places扩展配置值。 有关更多信息,请参阅 配置API参考.

必需 描述
places.libraries 适用于移动设备应用程序的Places扩展库。 它指定移动设备应用程序支持的库ID和库名称。
places.endpoint 默认的Places查询服务端点,用于获取有关库和POI的信息。
places.membershipttl 默认值为3600(以秒为单位)。 指示设备的Places成员资格信息将保持有效的时长(以秒为单位)。

在此页面上