Marketo Mobile SDK for iOS 0.7.6
Marketo Mobile SDK 允许与 Marketo Mobile Engagement (MME) 集成。
安装说明及其他信息请见 此处.
变更日志
v0.7.6 (2018 年 9 月 4 日)
- 修复了 In-app 中的 tap gesture 错误
v0.7.5 (2017 年 9 月 8 日)
- 修复了 Xcode 9 中的编译错误和警告
v0.7.4 (2017 年 7 月 7 日)
- 公开了 removeDevicePushToken() 方法
v0.7.1 (2016 年 11 月 24 日)
- 处理 iOS 10 中的 loadingOptions 通知,以跟踪应用关闭时的 tap 活动。
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
- 修复了新安装错误
- 修复了版本错误
v0.5.0
- 高级安全访问
- 重构 Bitcode
问题
如果您在使用或集成此插件时遇到问题,请在工作支持.marketo.com 上建立支持票据
Marketo iOS SDK 安装指南
前提条件
1. 在Marketo管理门户中注册应用程序,获取您的应用程序密钥和munchkin登录ID。
2. 配置安卓推送权限,了解更多。
这里。
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 中打开工作区。打开 App.xcworkspace
设置 Swift 桥接头
2. 文件命名 -Bridging-Header
3. 前往项目 > 目标 > 构建阶段 > Swift 编译器 - 代码生成 -> 将以下路径添加到 Objective-Bridging
#####头文件:$(PODS_ROOT)/-Bridging-Header.h
#SDK 初始化
在使用 Marketo iOS SDK 之前,您必须使用 Munchkin 账户 ID 和 App 密钥对其进行初始化。您可以在 Marketo 管理区域下的移动应用中找到这些信息。
1. 打开您的AppDelegate.m或Bridging文件(Swift)并导入Marketo.h头文件。
import <Marketo/Marketo.h>
2. 将以下代码粘贴到application:didFinishLaunchingWithOptions:函数内部。
Objective-C
Marketo *sharedInstance = [Marketo sharedInstance];
[sharedInstance initializeWithMunchkinID:@"munchkinAccountId" appSecret:@"secretKey" launchOptions:launchOptions];
Swift
let sharedInstance: Marketo = Marketo.sharedInstance()
sharedInstance.initializeWithMunchkinID("munchkinAccountId", appSecret: "secretKey", launchOptions: launchOptions)
3. 使用Munchkin账户ID和密钥替换上面的munkinAccountId和secretKey,这些可以在Marketo管理员的移动应用部分找到。
在苹果开发者账户上配置推送通知
1. 登录到苹果开发者会员中心。
2. 点击“证书、标识符和配置文档”。
3. 在“iOS、tvOS、watchOS”下的“证书->所有”文件夹中点击。
4. 选择屏幕右上角的“+”按钮。
5. 启用“Apple Push 通知服务 SSL(沙箱 & 生产)复选框,并点击“继续”。
6. 选择您用于构建应用程序的应用标识符。
7. 创建并上传 CSR 以生成推送证书。
8. 将证书下载到本地计算机,并双击进行安装。
9. 打开“密钥链访问”,右键点击证书,并将其导出为.p12文件中的两项。
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{
// ...
if ([UNUserNotificationCenter class])
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
}
}];
}
else if ([application respondsToSelector:@selector (registerUserNotificationSettings:)])
{
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
}
else
{
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
[application registerForRemoteNotifications];
// ...
}
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ...
if #available(iOS 10, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self;
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
}
else
{
application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
}
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. 处理推送通知:要处理从Marketo收到的推送通知,请将以下代码放入AppDelegate。
Objective-C
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[Marketo sharedInstance] handlePushNotification:userInfo];
}
Swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
Marketo.sharedInstance().handlePushNotification(userInfo)
}
6. 处理本地通知:要处理从Marketo SDK收到的本地通知,请将以下代码放入AppDelegate。它允许Marketo SDK在应用在前台时处理推送通知。
Objective-C
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[[Marketo sharedInstance] application:application didReceiveLocalNotification:notification];
}
Swift
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
Marketo.sharedInstance().application(application, didReceive: notification)
}
7. 在 AppDelegate 中添加以下方法:通过此方法,您可以在应用处于前台时显示警报、声音或增加角标。对于 iOS 10,您必须在此方法中调用您选择的 completionHandler。
Objective-C
#ifdef __IPHONE_10_0
- (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
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert) // OR
// completionHandler(.badge) OR
//completionHandler(.sound)
}
8. 在 AppDelegate iOS 10 中处理新接收到的推送通知:此方法将在用户通过打开应用、关闭通知或选择一个 UNNotificationAction 对通知做出响应时在代理上调用。必须在应用返回 applicationDidFinishLaunching: 之前设置代理。
Objective-C
#ifdef __IPHONE_10_0
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler {
[[Marketo sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif
Swift
@available(iOS 10.0, *)
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. 包含应用程序:openURL:sourceApplication:annotation:到AppDelegate.m
在AppDelegate中处理自定义URL类型
Objective-C
#ifdef __IPHONE_10_0
-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<NSString *,id> *)options{
return [[Marketo sharedInstance] application:application
openURL:url
sourceApplication:nil
annotation:nil];
}
#elif
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[Marketo sharedInstance] application:application
openURL:url
sourceApplication:nil
annotation:nil];
}
#endif
Swift
private func application(app: UIApplication, openURL url: URL, options: [String : AnyObject]) -> Bool {
return Marketo.sharedInstance().application(app, open: url, sourceApplication: nil, annotation: nil)
}
如何在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 移动管理中启用安全访问模式,设置 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()