Marketo-iOS-SDK 0.8.6

Marketo-iOS-SDK 0.8.6

测试测试
Lang语言 Obj-CObjective C
许可证 NOASSERTION
发布最后发布2024年4月

Mahesh BijapurJyoti Kalashetti维护。



  • Marketo,Adobe公司

Marketo Mobile SDK for iOS 0.8.2

Marketo Mobile SDK允许与Marketo Mobile Engagement (MME)集成。

安装说明和其他信息请在此处查看此处

变更日志

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日)

  • 修复了注销设备令牌的bug

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中的加载选项的 notification,以跟踪应用关闭时的点击活动。

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. 配置安卓推送访问,在这里学习
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 桥接头

#####1.转到File > New > File并选择Header文件:header

2. 将文件命名为-Bridging-Header
3. 转到Project->Target->Build Phases->Swift Compiler - Code Generation-> 将以下路径添加到Objective-Bridging

#####Header: $(PODS_ROOT)/-Bridging-Header.h header

SDK 初始化

在使用 Marketo iOS SDK 之前,您必须使用您的 Munchkin 账户 ID 和 App 密钥对其进行初始化。您可以在 Marketo 管理区域中的“移动应用”下找到每一个。
1. 打开您的 AppDelegate.m 或 Bridging 文件(Swift)并导入 Marketo.h 头文件。
import "Marketo.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帐户ID和密钥替换上面的munkinAccountId和secretKey,这些可以在Marketo管理员移动应用部分找到。

header

在Apple开发者会员中心配置推送通知

1. 登录到Apple开发者会员中心。
2. 点击“证书、标识符和配置文档”。
3. 点击“证书”->“所有”文件夹下的“iOS, tvOS, watchOS”。
4. 选择屏幕右上角的“+”按钮。

header

5. 打开“Apple Push 通知服务 SSL(沙盒 & 生产)”复选框,并点击“继续”。

header

6. 选择用于构建应用程序的应用程序标识符。

header

7. 创建 CSR 并上传以生成推送证书。

header

8. 将证书下载到本地计算机,并双击安装。

header

9. 打开“钥匙串访问”,右击证书,将 2 项导出为 .p12 文件。

header

10. 通过Marketo管理员控制台上传此文件以配置通知。

header

11. 更新应用程序配置文件。

## 在xCode中启用推送通知

1. 在xCode项目中启用推送通知功能。

header

## 使用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中添加以下方法:通过此方法,在应用程序处于前台时,您可以显示警报、声音或增加徽章。您必须在方法中调用您选择完成处理器。
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. 选择 Project -> Target -> Info -> URL Types
2. 添加标识符:${PRODUCT_NAME}
3. 设置 URL Schemes: mkto-

header

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 应访问新的端点,指向上面列出的算法,以检索设置签名对象所需字段。如果已在上的市场移动管理员中启用安全访问模式,则在 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()