Marketo Mobile SDK for iOS 0.8.5
Marketo Mobile SDK 允许与 Marketo Mobile Engagement (MME) 集成。
安装说明及其他信息请参阅 此处。
变更日志
v0.8.5 (2023年10月11日)
- 包含隐私清单文件和增强功能。
v0.8.4 (2023年8月10日)
- 增强功能和修复程序。
v0.8.3 (2023年7月24日)
- 为 iOS-SDK 添加了 Swift 包管理器支持。
- 修复程序和增强功能。
v0.8.2 (2023年6月26日)
- 添加对 XCFramework 的支持以支持多个平台。
v0.8.1 (2023年6月5日)
- 在初始化参数中包括开发框架类型(例如,本地、cordova、ionic 或 reactnative)
- 修复程序和增强功能
v0.8.0 (2023年3月6日)
- 升级 SDK 至支持最低 iOS 版本 12.0 及增强功能
v0.7.8 (2021年8月19日)
- 修复程序和增强功能
v0.7.7 (2020年3月6日)
- 修复了注销设备令牌的漏洞
v0.7.6 (2018年9月4日)
- 修复了 In-app 中的触摸手势错误
v0.7.5 (2017年9月8日)
- 修复了 xCode 9 中的构建错误和警告
v0.7.4 (2017年7月7日)
- 公开了 removeDevicePushToken() 方法
v0.7.1 (2016年11月24日)
- 在 iOS 10 中的 loadingOptions 中处理通知,以在应用程序关闭时跟踪触摸活动。
v0.7.0 (2016年10月5日)
- 在应用处于前台时使用 UNNotification 处理收到的推送并使用本地通知
v0.6.4 (2016年8月23日)
- 公开 [MarketoSDK reportAll] 方法以立即发送事件
v0.6.3 (2016年7月15日)
- 支持 InApp 显示频率一次。
v0.6.0 (2016年6月11日)
- InApp 通知
v0.5.1 - v0.5.3
- 修复 new_install 漏洞
- 修复版本漏洞
v0.5.0
- 高级安全访问
- 重构 Bitcode
问题
如果您在使用或集成此插件时遇到问题,请在 support.marketo.com 上创建支持票据
Marketo iOS SDK 安装指南
先决条件
1. 在 Marketo 管理门户中注册应用程序,获取您的应用程序密钥和 munchkin id。
2. 了解如何配置 Android 推送访问。
3. 配置 iOS 推送访问并了解此处。
通过 Cocoapods 安装框架
公开 removeDevicePushToken() 方法
1. 安装 CocoaPods。
sudo gem install cocoapods
2. 切换到您的项目目录并创建包含智能默认设置的 Podfile。
pod init
3. 打开您的 Podfile。
open -a Xcode Podfile
4. 在您的 Podfile 中添加以下行。
pod 'Marketo-iOS-SDK'
5. 保存并关闭您的 Podfile。
6. 下载并安装 Marketo iOS SDK。
pod install
7. 在 Xcode 中打开工作区。
open App.xcworkspace
使用 Swift 包管理器安装框架
1. 从项目导航器中选择项目,然后在“添加包依赖项”下单击以下所示“+”。
2. 从此仓库添加Marketo包。为此仓库添加此URL:https://github.com/Marketo/ios-sdk.git。
3. 现在添加资源包,如图所示:在项目导航器中定位 MarketoFramework.XCframework
并在finder中打开它。然后拖放 MKTResources.bundle
到 复制包资源
设置Swift桥接头
2. 将文件命名为 -Bridging-Header
3. 转到项目->目标->构建阶段->Swift编译器 - 代码生成->将以下路径添加到Objective-Bridging
#####头文件:$(PODS_ROOT)/-Bridging-Header.h
#SDK 初始化
在您可以使用Marketo iOS SDK之前,您必须使用Munchkin Account Id和App Secret Key进行初始化。您可以在Mobile Apps部分下的Marketo管理区域找到每个这些。
1. 打开您的AppDelegate.m或桥接文件(Swift)并导入Marketo.h头文件。
#import <MarketoFramework/MarketoFramework.h>
2. 在application:didFinishLaunchingWithOptions:函数中粘贴以下代码。
Objective-C
Marketo *sharedInstance = [Marketo sharedInstance];
[sharedInstance initializeWithMunchkinID:@"munchkinAccountId" appSecret:@"secretKey" mobileFrameworkType:@"native" launchOptions:launchOptions];
Swift
let sharedInstance: Marketo = Marketo.sharedInstance()
sharedInstance.initializeWithMunchkinID("munchkinAccountId", appSecret: "secretKey", mobileFrameworkType: "native", launchOptions: launchOptions)
3. 使用您的Munchkin Account Id和Secret Key替换上面的munkinAccountId和secretKey,您可以在Marketo管理器的Mobile Apps部分中找到这些。
#在Apple开发者账户上配置推送通知
1. 登录到Apple开发者会员中心。
2. 点击 “证书、标识符和配置文档”。
3. 点击 “证书->iOS、tvOS、watchOS”下的 “所有证书” 文件夹。
4. 点击屏幕右上方的“+”按钮。
5. 启用“Apple推送通知服务SSL(沙盒和生产)”复选框,然后点击“继续”。
6. 选择您用于构建应用的应用标识符。
7. 创建并上传CSR以生成推送证书。
8. 将证书下载到本地计算机并双击以安装。
9. 打开 “密钥链访问”,右键单击证书,并将其导出为.p12文件,导出2个项目。
10. 通过Marketo管理控制台上传此文件以配置通知。
11. 更新应用程序配置文件。
#在xCode中启用推送通知
1. 在xCode项目中启用推送通知功能。
#在带有Marketo SDK的应用中启用推送通知
1. 在AppDelegate.h中导入以下内容。
Objective-C
#import <UserNotifications/UserNotifications.h>
Swift
import UserNotifications
2. 如下所示,将UNUserNotificationCenterDelegate添加到AppDelegate中。
Objective-C
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
Swift
class AppDelegate: UIResponder, UIApplicationDelegate , UNUserNotificationCenterDelegate
3. 启动推送通知服务:要启用推送通知,请添加以下代码。
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// ...
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];
// ...
}
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ...
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if let error = error {
print("\(error.localizedDescription)")
} else {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
// ...
}
4. 注册推送令牌
Objective-C
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Register the push token with Marketo
[[Marketo sharedInstance] registerPushDeviceToken:deviceToken];
}
Swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Register the push token with Marketo
Marketo.sharedInstance().registerPushDeviceToken(deviceToken)
}
此令牌也可以注销
Objective-C
[[Marketo sharedInstance] unregisterPushDeviceToken];
Swift
Marketo.sharedInstance().unregisterPushDeviceToken
5. 在AppDelegate中添加以下方法:通过此方法,您可以在应用处于前台时显示提示、播放声音或增加徽标。您必须在此方法中调用您选择的completionHandler。
Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"Notification is triggered");
completionHandler(UNNotificationPresentationOptionAlert); // OR
// completionHandler(UNNotificationPresentationOptionBadge); OR
// completionHandler(UNNotificationPresentationOptionSound);
#endif
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert) // OR
// completionHandler(.badge) OR
//completionHandler(.sound)
}
6. 处理AppDelegate中接收到的新的推送通知:当用户通过打开应用、取消通知或选择UNNotificationAction响应该通知时,该方法将在代理中被调用。在应用程序返回applicationDidFinishLaunching:之前必须设置代理。
Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler {
[[Marketo sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
Marketo.sharedInstance().userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
}
#iOS 测试设备
1. 选择项目->目标->信息->URL 类型
2. 添加标识符:${PRODUCT_NAME}
3. 设置URL方案:mkto-
5. 在AppDelegate.m中包含了application:openURL:sourceApplication:annotation:
在AppDelegate中处理自定义URL类型
Objective-C
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return [[Marketo sharedInstance] application:app
openURL:url
options:nil];
}
Swift
private func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
{
return Marketo.sharedInstance().application(app, open: url, options: options)
}
#如何在iOS上创建用户配置文件
1. 创建用户配置文件
您可以通过以下方式发送用户字段来创建丰富的配置文件。
Objective-C
MarketoLead *profile = [[MarketoLead alloc] init];
// Get user profile from network and populate
[profile setEmail:@"[email protected]"];
[profile setFirstName:@"John"];
[profile setLastName:@"Doe"];
[profile setAddress:@"1234KingFishSt"];
[profile setCity:@"SouthPadreIsland"];
[profile setState:@"CA"];
[profile setPostalCode:@"78596"];
[profile setCountry:@"USA"];
[profile setGender:@"male"];
[profile setLeadSource:@"_facebook_ads"];
[profile setBirthDay:@"01/01/1985"];
[profile setFacebookId:@"facebookid"];
[profile setFacebookProfileURL:@"facebook.com/profile"];
[profile setFacebookProfilePicURL:@"faceboook.com/profile/pic"];
[profile setLinkedInId:@"linkedinid"];
[profile setTwitterId:@"twitterid"];
Swift
let profile = MarketoLead()
// Get user profile from network and populate
profile.setEmail("[email protected]")
profile.setFirstName("John")
profile.setLastName("Doe")
profile.setAddress("1234KingFishSt")
profile.setCity("SouthPadreIsland")
profile.setState("CA")
profile.setPostalCode("78596")
profile.setCountry("USA")
profile.setGender("male")
profile.setLeadSource("_facebook_ads")
profile.setBirthDay("01/01/1985")
profile.setFacebookId("facebookid")
profile.setFacebookProfileURL("facebook.com/profile")
profile.setFacebookProfilePicURL("faceboook.com/profile/pic")
profile.setLinkedInId("linkedinid")
profile.setTwitterId("twitterid")
2. 添加更多标准字段
Objective-C
// Add other custom fields
[profile setFieldName:@"mobilePhone"withValue:@"123.456.7890"];
[profile setFieldName:@"numberOfEmployees"withValue:@"10"];
[profile setFieldName:@"phone"withValue:@"123.456.7890"];
Swift
profile.setFieldName("mobilePhone" , withValue :"123.456.7890");
profile.setFieldName("numberOfEmployees", withValue: "10");
profile.setFieldName("phone", withValue:"123.456.7890");
3. 报告用户配置文件
Objective-C
Marketo *sharedInstance = [Marketo sharedInstance];
// This method will update user profile
[sharedInstance associateLead:profile];
Swift
let marketo = Marketo.sharedInstance()
// This method will update user profile
marketo.associateLead(profile)
如何在iOS上发送自定义动作
您可以通过发送自定义动作来跟踪用户交互。
1. 发送自定义动作。
Objective-C
Marketo *sharedInstance = [Marketo sharedInstance];
[sharedInstance reportAction:@"Login" withMetaData:nil];
2. 添加自定义动作元数据。
Objective-C
MarketoActionMetaData *meta = [[MarketoActionMetaData alloc] init];
[meta setType:@"Shopping"];
[meta setDetails:@"RedShirt"];
[meta setLength:20];
[meta setMetric:30];
[sharedInstance reportAction:@"Bought Shirt" withMetaData:meta];
Swift
let meta = MarketoActionMetaData()
meta.setType("Shopping");
meta.setDetails("RedShirt");
meta.setLength(20);
meta.setMetric(30);
sharedInstance.reportAction("Bought Shirt", withMetaData:meta);
高级安全访问模式
Marketo SDK公开了设置和删除安全签名的方法。还有一个实用方法可以检索设备ID。设备ID应在登录时与电子邮件一起传递到客户服务器,用于计算安全签名。SDK应调用指向上述算法的新端点,以检索实例化签名对象的必要字段。如果已启用Marketo Mobile Admin中的安全访问模式,则在SDK中设置此签名是必要步骤。有关高级安全访问模式的更多信息,请点击此处此处。
Objective-C
Marketo * sharedInstance =[Marketo sharedInstance];
// set secure signature
MKTSecuritySignature *signature =
[[MKTSecuritySignature alloc] initWithAccessKey:<ACCESS_KEY> signature:<SIGNATURE_TOKEN> timestamp:<EXPIRY_TIMESTAMP> email:<EMAIL>];
[sharedInstance setSecureSignature:signature];
[sharedInstance removeSecureSignature];
[sharedInstance getDeviceId];
Swift
let sharedInstance = Marketo.sharedInstance()
// set secure signature
let signature = MKTSecuritySignature(accessKey: <ACCESS_KEY>, signature: <SIGNATURE_TOKEN> , timestamp: <EXPIRY_TIMESTAMP>, email: <EMAIL>)
sharedInstance.setSecureSignature(signature)
[sharedInstance removeSecureSignature];
sharedInstance.getDeviceId()