要使用Places Monitor扩展,请完成以下任务:
Places Monitor扩展没有配置任务。
下面介绍如何将Places Monitor扩展添加到Android或iOS应用程序。
对Places Monitor扩展的其他平台支持包括:Cordova Places Monitor
在Android中,完成以下步骤:
使用应用程序的格式文件,将“地点监视器”扩展和“地点”扩展添加到您的项目。
在Gradle文件中还包含最新的Google Location服务。
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'
在应用程序的主活动中导入地点监视器扩展。
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中注册并开始位置监视器。
在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 Monitor 扩展时,请确保同时将 places.aar
库添加到项目中。
在iOS应用程序中application:didFinishLaunchingWithOptions
,使用 PlacesMonitor
Mobile Core注册和放置:
- (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
则该键也是必需的。