MBTestSDKMB 0.0.1

MBTestSDKMB 0.0.1

Maintained by Mahesh Bijapur.



  • By
  • Marketo an Adobe Company

Marketo Mobile SDK for iOS 0.0.1

Issues

If you encounter issues using or integrating this plugin, please file a support ticket at support.marketo.com

Marketo iOS SDK Installation Guide

Prerequisites

1. Register an application in Marketo Admin portal, get your application secret key and munchkin id.
2. Configure Android Push access learn here
3. Configure iOS Push access learn here.

Install Framework via cocoapods

Expose removeDevicePushToken() method

1. Install CocoaPods.
sudo gem install cocoapods
2. Change directory to your project directory and create a Podfile with smart defaults.
pod init
3. Open your Podfile.
open -a Xcode Podfile
4. Add the following line to your Podfile.
pod 'Marketo-iOS-SDK'
5. Save and close your Podfile.
6. Download and install Marketo iOS SDK.
pod install
7. Open workspace in Xcode. open App.xcworkspace

Setup Swift Bridging Header

#####1. Go to File > New > File and Select Header File: header

2. Name the file -Bridging-Header
3. Go to Project->Target->Build Phases->Swift Compiler - Code Generation-> Add the following path to Objective-Bridging

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

#SDK Initialization

Before you can use the Marketo iOS SDK, you must initialize it with your Munchkin Account Id and App Secret Key. You can find each of these in the Marketo Admin area underneath Mobile Apps.
1. Open your AppDelegate.m or Bridging file (Swift) and import the Marketo.h header file.
import <Marketo/Marketo.h>
2. Paste the following code inside the application:didFinishLaunchingWithOptions: function.
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. Replace munkinAccountId and secretKey above using your Munchkin Account Id and Secret Key which are found in the Marketo Admin Mobile Apps section.

header

#Configure Push Notifications on Apple Developer Account

1. Log into the Apple Developer Member Center.
2. Click on �Certificates, Identifiers & Profiles�.
3. Click on �Certificates->All� folder underneath �iOS, tvOS, watchOS�.
4. Select the �+� the button on the top right of the screen.

header

5. Enable �Apple Push Notification service SSL (Sandbox & Production)� checkbox, and click �Continue�.

header

6. Select the application identifier that you are using the build the app.

header

7. Create and upload CSR to generate the push certificate.

header

8. Download certificate to local computer and double-click to install.

header

9. Open �Keychain Access�, right click on the certificate, and export 2 items into .p12 file.

header

10. Upload this file through Marketo Admin Console to configure notifications.

header

11. Update app provisioning profiles.

#Enable Push Notifications in xCode

1. Turn on push notification capability in xCode project.

header

#Enable Push Notifications in App with Marketo SDK

1. Import following in AppDelegate.h.
Objective-C
#import <UserNotifications/UserNotifications.h>
Swift
import UserNotifications
2. Add UNUserNotificationCenterDelegate to AppDelegate as shown below.
Objective-C
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
Swift
class AppDelegate: UIResponder, UIApplicationDelegate , UNUserNotificationCenterDelegate
3. Initiate Push notification Service : To enable push notification add below code.
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. Register Push Token
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)
}
The token can also be unregistered
Objective-C
[[Marketo sharedInstance] unregisterPushDeviceToken];
Swift
Marketo.sharedInstance().unregisterPushDeviceToken
5. Handle push notification : To handle push notifications received from Marketo, put the following code in 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. Handle Local notification : To handle Local notifications received from Marketo SDK, put the following code in AppDelegate. It allows Marketo SDK to handle push notification while app is in foreground.
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. Add the following method in AppDelegate : By using this method you can either present alert, sound or increase badge while the app is in foreground with iOS 10. You must call completionHandler of your choice in this Method.
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. Handle newly received Push notification in AppDelegate iOS 10 : The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from 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 Test Devices

1. Select Project->Target->Info->URL Types
2. Add identifier: ${PRODUCT_NAME}
3. Set URL Schemes: mkto-

header

5.Include application:openURL:sourceApplication:annotation: to AppDelegate.m

Handle Custom Url Type in AppDelegate

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

#How to Create User Profiles on iOS

1. Create User Profile
You can create rich profiles by sending user fields as shown below.
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. Add more Standard Fields
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. Report User Profile
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)

#How to Send Custom Actions on iOS

You can track user interactions by sending custom actions.
1. Send custom action.
Objective-C
Marketo *sharedInstance = [Marketo sharedInstance];

[sharedInstance reportAction:@"Login" withMetaData:nil];
2. Add custom action meta data.
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);

Advanced Security Access Mode

The Marketo SDK exposes methods to set and remove the security signature. There is also a utility method to retrieve the device ID. The device ID should be passed along with the email, upon login, to the customer server for use in calculating the security signature. The SDK should the hit new endpoint, pointing to algorithm listed above, to retrieve the necessary fields to instantiate the signature object. Setting this signature in the SDK is a necessary step if the Security Access Mode has been enabled in Marketo Mobile Admin. learn more about Advanced Security Access Mode here.
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()

Xcode 10 Project Configeration

Click on File —-> workspace settings --> change New build system to Legacy build system header