Places擴充功能可讓您根據使用者的位置採取行動。 此擴充功能是Places Query Service API的介面。 透過監聽包含GPS座標和地理區域事件的事件,此擴充功能會派送規則引擎處理的新事件。 Places擴充功能也會擷取並傳送從API擷取之應用程式資料的最近POI清單。 API傳回的區域會儲存在快取和永續性中,允許有限的離線處理。
In Experience Platform Launch, click the Extensions tab.
在標籤 Catalog 上,找到擴 Places 展名,然後按一下 Install。
選擇要在此屬性中使用的「置入」庫。 這些是您應用程式中可存取的資料庫。
按一下「Save」。
當您按一下 Save時,Experience Platform SDK會在您選取的程式庫中,搜尋Places Services中的POI。 當您建立應用程式時,程式庫的下載中不會包含POI資料,但POI的位置子集會在執行時期下載至使用者裝置,並以使用者的GPS座標為基礎。
完成發佈程式以更新SDK組態。
如需有關在Experience Platform Launch中發佈的詳細資訊,請參閱 發佈。
您可以將Places擴充功能新增至Android和iOS應用程式。 將「位置」新增至iOS或Android應用程式的步驟如下所示。 下列平台也提供Places擴充功能。 如需在使用其中一種平台進行開發時新增「地標」至您的應用程式,請參閱隨附的連結:
若要使用Java將Places擴充功能新增至您的應用程式:
使用應用程式的Gradle檔案,將Places擴充功能新增至您的專案。
implementation 'com.adobe.marketing.mobile:places:1.+'
implementation 'com.adobe.marketing.mobile:sdk-core:1.+'
在應用程式的主要活動中匯入「位置」擴充功能。
import com.adobe.marketing.mobile.Places;
若要使用Objective-C或Swift將Places擴充功能新增至您的應用程式:
將「地標」和「 行動核心 」程式庫新增至您的專案。 您需要將下列Pod新增至您的 Podfile
:
pod 'ACPPlaces', '~> 1.0'
pod 'ACPCore', '~> 2.0' # minimum Core version for Places is 2.0.3
或者,如果您不使用Cocoapods,則可從Github的發行頁面手動加入Mobile Core和 Places程式庫 。
更新您的Cocoapod:
pod update
開啟Xcode,然後在您的AppDelegate類別中匯入「核心」和「位置」標題:
Objective-C
#import "ACPCore.h"
#import "ACPPlaces.h"
Swift
import ACPCore
import ACPPlaces
您必須在Android和iOS中使用Mobile Core註冊Places擴充功能。
在您應用程式的方法中, OnCreate
註冊「地標」擴充功能:
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());
}
}
}
在您的應用程式方 application:didFinishLaunchingWithOptions:
法中,將Places擴充功能註冊至您的其他SDK註冊呼叫:
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.membershipttl
時間。 傳入的值代表「置入」狀態對裝置維持有效的秒數。
在回呼中, 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());
}
}
}
在回呼方法的第一行 ACPCore
中, 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 Query Service端點,用於獲取有關庫和POI的資訊。 |
places.membershipttl |
無 | 預設值3600(一小時內的秒數)。 指出裝置的「置入」會籍資訊的有效期(以秒為單位)。 |