要使用Places Monitor擴展,請完成以下任務:
Places Monitor擴展沒有配置任務。
以下說明如何將Places Monitor擴充功能新增至Android或iOS應用程式。
Places Monitor擴充功能的其他平台支援包括:Cordova Places Monitor
在Android中,完成下列步驟:
使用應用程式的Gradle檔案,將Places Monitor擴充功能和Places擴充功能新增至您的專案。
此外,在Gradle檔案中也包含最新的Google位置服務。
implementation 'com.adobe.marketing.mobile:places:1.+'
implementation 'com.adobe.marketing.mobile:places-monitor:1.+'
implementation 'com.adobe.marketing.mobile:sdk-core:1.+'
implementation 'com.google.android.gms:play-services-location:16.0.0'
在應用程式的主要活動中匯入Places Monitor擴充功能。
import com.adobe.marketing.mobile.PlacesMonitor;
在iOS中,完成下列步驟:
Podfile
by adding pod 'ACPPlacesMonitor'
.#import "ACPCore.h"
#import "ACPPlaces.h"
#import "ACPPlacesMonitor.h"
import ACPCore
import ACPPlaces
import ACPPlacesMonitor
您必須註冊並啟動Android或iOS中的Places Monitor。
在Android中,完成下列步驟:
在您應用程式的方法中, OnCreate
註冊Places Monitor擴充功能:
public class MobileApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
MobileCore.ConfigureWithAppId("yourAppId");
try {
PlacesMonitor.registerExtension(); //Register PlacesMonitor with Mobile Core
Places.registerExtension(); //Register Places with Mobile Core
MobileCore.start(null);
PlacesMonitor.start();//Start monitoring the geo-fences
} catch (Exception e) {
//Log the exception
}
}
}
位置監控取決於位置擴展。 手動安裝「Places 監視」擴充功能時,請確定您也將 places.aar
資料庫新增至專案。
在iOS應用程式中application:didFinishLaunchingWithOptions
,註冊 PlacesMonitor
並放置行動核心:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[ACPCore configureWithAppId:@"yourAppId"];
[ACPPlaces registerExtension];
[ACPPlacesMonitor registerExtension];
[ACPCore start:^{
// do other initialization required for the SDK
[ACPPlacesMonitor start];
}];
return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ACPCore.configure(withAppId: "yourAppId")
ACPPlaces.registerExtension()
ACPPlacesMonitor.registerExtension()
ACPCore.start({
// do other initialization required for the SDK
ACPPlacesMonitor.start()
})
// Override point for customization after application launch.
return true
}
位置監控取決於位置擴展。 When manually installing the Places Monitor extension, ensure that you also add the libACPPlaces_iOS.a
library to your project.
Java
對於所有Android版本,若要宣告您的應用程式需要位置權限,請在應用程式資訊清單中新增元素,作為頂層元素的子項 <uses-permission>
<manifest>
。 針對以API等級29及更高版本為目標的Android應用程式,若要允許應用程式存取背景中的位置,請加入ACCESS_BACKGROUND_LOCATION權限。
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.adobe.placesapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
// Only for Android apps targeting API level 29 and above
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application>
...
</application>
</manifest>
iOS支援將位置事件傳送至已暫停或不再執行的應用程式。 若要在背景接收Places Monitor擴充功能的位置更新,請在中設定您應用程式的位置更新功能 Xcode.background-location-updates
。
您的應用程式檔案中必須包含下列金 Info.plist
鑰:
NSLocationWhenInUseUsageDescription
-文字應說明應用程式在前景中執行時要求存取使用者位置資訊的原因。NSLocationAlwaysAndWhenInUseUsageDescription
-文字應說明應用程式為何會隨時要求存取使用者的位置資訊。如果您的應用程式支援iOS 10及更早版本,則 NSLocationAlwaysUsageDescription
也需要金鑰。