Skip to content

Commit

Permalink
Merge pull request #149 from hellohaptik/example-manual
Browse files Browse the repository at this point in the history
Added Example Project for Manual Linking
  • Loading branch information
iamsimranjot authored Oct 4, 2019
2 parents d54fd4b + d8c067e commit f7a7f64
Show file tree
Hide file tree
Showing 62 changed files with 4,039 additions and 59 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions Examples/Shared/haptik_textLogo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "haptik_textlogo.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
132 changes: 132 additions & 0 deletions Examples/Swift-Example-Manual/Swift-Example-Manual/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// AppDelegate.swift
// Swift-Example-Manual
//
// Created by SimranJot Singh on 04/10/19.
// Copyright © 2019 Haptik. All rights reserved.
//

import UIKit
import HaptikLib
import HaptikBase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// Required at the Initial Launch of the Application
Haptik.sharedSDK().notify(application, launchedWithOptions: launchOptions)

// Required for Enterprise Clients
HPConfiguration.shared().useInbox = false;

//


// If you need the callbacks of the analytics data that haptik sends
HPConfiguration.shared().analyticsCallbackObject = self;

// Setup UI Theme for Haptik
setHaptikTheme()

// Interactive Pop Gesture

// This BOOL controls the functionality of the EdgePanGestureRecognizer feature of UINavigationController
// that allows to set the slide to go back functionality for Haptik Screens. By default the value will be true.

HPConfiguration.shared().useInteractivePopGesture = true

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

// Let Haptik handle the redirect if required

let isHandledByHaptik = Haptik.sharedSDK().isRedirectHandled(url, options: options)
return isHandledByHaptik
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

// You need to pass the Device Token after the user successfully signs up in Haptik. Till that you need to store it in your application.

UserDefaults.standard.set(deviceToken, forKey: "kDeviceToken")
UserDefaults.standard.synchronize()
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

// Check if the notification received belongs to haptik and take action accordingly

let isHaptikNotification = Haptik.sharedSDK().canHandleNotification(userInfo: userInfo as! [String : Any])

if isHaptikNotification {

print("Do Housekeeping")
handleNotificationInteraction(userInfo as! [String : Any])
}
}
}

//MARK: Helper Methods

extension AppDelegate {

func handleNotificationInteraction(_ userInfo: [String: Any]) {

if let rootVC = self.window?.rootViewController {
if let controller = rootVC as? UINavigationController {

// You need to pass an instance of a viewController from which the user will be taken to the conversationViewController (where the user will be conversing)
// on the tap of the Notificationm
Haptik.sharedSDK().didReceiveRemoteNotification(userInfo, controller: controller.visibleViewController!)

}
}
}

func setHaptikTheme() {

// NOTE: Haptik only gives instances of viewControllers. When you push them on your stack, the navigationBar is still the yours, hence it's appearance too.

// The following there configuration is the default configuration. If you don't provide one then the SDK will try to adopt the following.

HPConfiguration.shared().themeConfig = HPThemeService.build { (builder) in

builder?.brandColor = UIColor(hexString: "#2196f3")
builder?.businessChatBackground = UIColor(hexString: "#f0f0f0")
builder?.businessChatText = UIColor(hexString: "#333333")
builder?.messageTimeStamp = UIColor(hexString: "#777777")

// Providing Fonts are Madatory else the SDK will Assert

builder?.lightFont = "SFUIText-Light"
builder?.regularFont = "SFUIText-Regular"
builder?.mediumFont = "SFUIText-Medium"
builder?.boldFont = "SFUIText-Bold"
builder?.semiBoldFont = "SFUIText-Semibold"
builder?.italicFont = "SFUIText-Italic"
}
}
}


// MARK: - HPAnalytics Service Delegates

extension AppDelegate: HPAnalyticsServiceDelegate {

func eventTracked(_ eventName: String, forParams params: [AnyHashable : Any]?) {

// Get all the events tracked here
}

func errorTracked(_ errorMessage: String, forError error: Error?) {

// Get all the errors tracked here
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// RootViewController.swift
// Swift-Example-Manual
//
// Created by SimranJot Singh on 04/10/19.
// Copyright © 2019 Haptik. All rights reserved.
//

import UIKit
import HaptikLib

class RootViewController: UIViewController {

// MARK: Outlets & Attributes

@IBOutlet weak var signupBtn: UIButton!
@IBOutlet weak var loadingIndicator: UIActivityIndicatorView!


// MARK: Controller Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}


// MARK: Actions

@IBAction func signupTapped(_ sender: UIButton) {

if Haptik.sharedSDK().isUserSignedUp() {

// NOTE: For Publishers:
// initialVC gives a list of channels that are available to that client

// Haptik.sharedSDK().getInitialVC() gives you the initialVC that you can push on your stack

// NOTE: For Enterprise:
// You don't need to push to the initialVC that Haptik gives. You need to directly go to the conversation channel with the "viaName" that will be provided to you.
// You can use:

/*Haptik.sharedSDK().launchChannel(with: "provided_via_name",
message: "any_message_you_wanna_start_With",
controller: <#instance_of_vc_from_which_the_conversationVC_is_pushed#>)*/
}
else {

loadingIndicator.startAnimating()
signupBtn.isHidden = loadingIndicator.isAnimating

let signupObject = HPSignUpObject.build(withAuthType: "basic") { (builder) in

builder.userFullName = "Simranjot"

// You can set more properties on the builder according to the requirements
}

Haptik.sharedSDK().signUp(with: signupObject) { [unowned self] (success, initialVC, error) in

if success {

// From here you can either push to the specific conversation controller or to the list of channel controller according to your requirements
}
else {

// Handle Error here
}

self.loadingIndicator.stopAnimating()
self.signupBtn.isHidden = self.loadingIndicator.isAnimating
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// PINCache is a modified version of TMCache
// Modifications by Garrett Moon
// Copyright (c) 2015 Pinterest. All rights reserved.

#import <Foundation/Foundation.h>

#import <PINCache/PINCacheMacros.h>
#import <PINCache/PINCaching.h>
#import <PINCache/PINDiskCache.h>
#import <PINCache/PINMemoryCache.h>

NS_ASSUME_NONNULL_BEGIN

@class PINCache;


/**
`PINCache` is a thread safe key/value store designed for persisting temporary objects that are expensive to
reproduce, such as downloaded data or the results of slow processing. It is comprised of two self-similar
stores, one in memory (<PINMemoryCache>) and one on disk (<PINDiskCache>).
`PINCache` itself actually does very little; its main function is providing a front end for a common use case:
a small, fast memory cache that asynchronously persists itself to a large, slow disk cache. When objects are
removed from the memory cache in response to an "apocalyptic" event they remain in the disk cache and are
repopulated in memory the next time they are accessed. `PINCache` also does the tedious work of creating a
dispatch group to wait for both caches to finish their operations without blocking each other.
The parallel caches are accessible as public properties (<memoryCache> and <diskCache>) and can be manipulated
separately if necessary. See the docs for <PINMemoryCache> and <PINDiskCache> for more details.
@warning when using in extension or watch extension, define PIN_APP_EXTENSIONS=1
*/

PIN_SUBCLASSING_RESTRICTED
@interface PINCache : NSObject <PINCaching, PINCacheObjectSubscripting>

#pragma mark -
/// @name Core

/**
Synchronously retrieves the total byte count of the <diskCache> on the shared disk queue.
*/
@property (readonly) NSUInteger diskByteCount;

/**
The underlying disk cache, see <PINDiskCache> for additional configuration and trimming options.
*/
@property (readonly) PINDiskCache *diskCache;

/**
The underlying memory cache, see <PINMemoryCache> for additional configuration and trimming options.
*/
@property (readonly) PINMemoryCache *memoryCache;

#pragma mark - Lifecycle
/// @name Initialization

/**
A shared cache.
@result The shared singleton cache instance.
*/
@property (class, strong, readonly) PINCache *sharedCache;

- (instancetype)init NS_UNAVAILABLE;

/**
Multiple instances with the same name are *not* allowed and can *not* safely
access the same data on disk. Also used to create the <diskCache>.
@see name
@param name The name of the cache.
@result A new cache with the specified name.
*/
- (instancetype)initWithName:(nonnull NSString *)name;

/**
Multiple instances with the same name are *not* allowed and can *not* safely
access the same data on disk. Also used to create the <diskCache>.
@see name
@param name The name of the cache.
@param rootPath The path of the cache on disk.
@result A new cache with the specified name.
*/
- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath;

/**
Multiple instances with the same name are *not* allowed and can *not* safely
access the same data on disk.. Also used to create the <diskCache>.
Initializer allows you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization for <diskCache>.
You must provide both serializer and deserializer, or opt-out to default implementation providing nil values.
@see name
@param name The name of the cache.
@param rootPath The path of the cache on disk.
@param serializer A block used to serialize object before writing to disk. If nil provided, default NSKeyedArchiver serialized will be used.
@param deserializer A block used to deserialize object read from disk. If nil provided, default NSKeyedUnarchiver serialized will be used.
@result A new cache with the specified name.
*/
- (instancetype)initWithName:(NSString *)name
rootPath:(NSString *)rootPath
serializer:(nullable PINDiskCacheSerializerBlock)serializer
deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer;


/**
Multiple instances with the same name are *not* allowed and can *not* safely
access the same data on disk. Also used to create the <diskCache>.
Initializer allows you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization for <diskCache>.
You must provide both serializer and deserializer, or opt-out to default implementation providing nil values.
@see name
@param name The name of the cache.
@param rootPath The path of the cache on disk.
@param serializer A block used to serialize object before writing to disk. If nil provided, default NSKeyedArchiver serialized will be used.
@param deserializer A block used to deserialize object read from disk. If nil provided, default NSKeyedUnarchiver serialized will be used.
@param keyEncoder A block used to encode key(filename). If nil provided, default url encoder will be used
@param keyDecoder A block used to decode key(filename). If nil provided, default url decoder will be used
@result A new cache with the specified name.
*/
- (instancetype)initWithName:(nonnull NSString *)name
rootPath:(nonnull NSString *)rootPath
serializer:(nullable PINDiskCacheSerializerBlock)serializer
deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer
keyEncoder:(nullable PINDiskCacheKeyEncoderBlock)keyEncoder
keyDecoder:(nullable PINDiskCacheKeyDecoderBlock)keyDecoder NS_DESIGNATED_INITIALIZER;

@end

@interface PINCache (Deprecated)
- (void)containsObjectForKey:(NSString *)key block:(PINCacheObjectContainmentBlock)block __attribute__((deprecated));
- (void)objectForKey:(NSString *)key block:(PINCacheObjectBlock)block __attribute__((deprecated));
- (void)setObject:(id <NSCoding>)object forKey:(NSString *)key block:(nullable PINCacheObjectBlock)block __attribute__((deprecated));
- (void)setObject:(id <NSCoding>)object forKey:(NSString *)key withCost:(NSUInteger)cost block:(nullable PINCacheObjectBlock)block __attribute__((deprecated));
- (void)removeObjectForKey:(NSString *)key block:(nullable PINCacheObjectBlock)block __attribute__((deprecated));
- (void)trimToDate:(NSDate *)date block:(nullable PINCacheBlock)block __attribute__((deprecated));
- (void)removeAllObjects:(nullable PINCacheBlock)block __attribute__((deprecated));
@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit f7a7f64

Please sign in to comment.