Skip to content

Commit

Permalink
Add Helpshift Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
icodesign committed Jul 23, 2016
1 parent 2463a5e commit cd12a0b
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public struct LifeCycleKey {
public static let didEnterBackground = "didEnterBackground"
public static let willEnterForeground = "willEnterForeground"
public static let didBecomeActive = "didBecomeActive"
public static let didRegisterForRemoteNotificationsWithDeviceToken = "didRegisterForRemoteNotificationsWithDeviceToken"
public static let didReceiveRemoteNotificationFetchCompletionHandler = "didReceiveRemoteNotificationFetchCompletionHandler"
public static let remoteNotification = "remoteNotification"
public static let willTerminate = "willTerminate"
public static let openURL = "openURL"
}
Expand Down
12 changes: 10 additions & 2 deletions Library/ICSMainFramework/ICSMainFramework/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}

public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.didRegisterForRemoteNotificationsWithDeviceToken] {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
}

public func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
}
}

public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.didReceiveRemoteNotificationFetchCompletionHandler] {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
}
Expand Down
18 changes: 16 additions & 2 deletions Library/ICSMainFramework/ICSMainFramework/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ public struct AppEnv {
}

public static var isTestFlight: Bool {
return isAppStoreReceiptSandbox && !hasEmbeddedMobileProvision
}

public static var isAppStore: Bool {
if isAppStoreReceiptSandbox || hasEmbeddedMobileProvision {
return false
}
return true
}

private static var isAppStoreReceiptSandbox: Bool {
return NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
}



private static var hasEmbeddedMobileProvision: Bool {
return NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") != nil
}

}
2 changes: 1 addition & 1 deletion PacketProcessor/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>108</string>
<string>110</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion PacketTunnel/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>108</string>
<string>110</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def library
pod 'KissXML/libxml_module'
pod 'ICSMainFramework', :path => "./Library/ICSMainFramework/"
pod 'MMWormhole', '~> 2.0.0'
pod 'KeychainAccess'
end

def tunnel
Expand Down
36 changes: 20 additions & 16 deletions Potatso.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
B86B08EC1D17F85800613014 /* ShadowPath.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B86B08E91D17F84900613014 /* ShadowPath.framework */; };
B86B08ED1D17FB9B00613014 /* ShadowPath.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B86B08E91D17F84900613014 /* ShadowPath.framework */; };
B87A043A1D193ABC001132F2 /* LoggerUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87A04391D193ABC001132F2 /* LoggerUtils.swift */; };
B87A72B41D433ACA006C2A1B /* NotificationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87A72B31D433ACA006C2A1B /* NotificationHandler.swift */; };
B87B98041D3B423B00FA66BF /* PaddingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87B98031D3B423B00FA66BF /* PaddingLabel.swift */; };
B87B980A1D3B64BE00FA66BF /* RequestEventRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87B98091D3B64BE00FA66BF /* RequestEventRow.swift */; };
B88096B01D0579F5008BEB87 /* CloudDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88096AF1D0579F5008BEB87 /* CloudDetailViewController.swift */; };
Expand Down Expand Up @@ -856,6 +857,7 @@
B84551411CF878BD005779CD /* ConfigGroupChooseVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigGroupChooseVC.swift; sourceTree = "<group>"; };
B86B08E31D17F84900613014 /* ShadowPath.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ShadowPath.xcodeproj; path = Library/ShadowPath/ShadowPath.xcodeproj; sourceTree = SOURCE_ROOT; };
B87A04391D193ABC001132F2 /* LoggerUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoggerUtils.swift; sourceTree = "<group>"; };
B87A72B31D433ACA006C2A1B /* NotificationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationHandler.swift; sourceTree = "<group>"; };
B87B98031D3B423B00FA66BF /* PaddingLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingLabel.swift; sourceTree = "<group>"; };
B87B98091D3B64BE00FA66BF /* RequestEventRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestEventRow.swift; sourceTree = "<group>"; };
B88096AF1D0579F5008BEB87 /* CloudDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CloudDetailViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1050,6 +1052,7 @@
9BC8589F1C33B00200992032 /* Potatso-Bridge-Header.h */,
9B0CFA0E1C1C0B1B007BD7C6 /* AppDelegate.swift */,
9B1F745F1C2F84250028C1A6 /* AppInitializer.swift */,
B87A72B31D433ACA006C2A1B /* NotificationHandler.swift */,
9B2290FE1C8E5B9600EEC901 /* DataInitializer.swift */,
9B8193EC1CBE4DCA00BE320D /* UrlHandler.swift */,
9B1F74611C2F85540028C1A6 /* UIManager.swift */,
Expand Down Expand Up @@ -2858,6 +2861,7 @@
9B17F8EB1C53379700679FCB /* SettingsViewController.swift in Sources */,
B8F7845C1D36760D00F02FF5 /* DashboardVC.swift in Sources */,
B803A6981D02B768003EA9AA /* API.swift in Sources */,
B87A72B41D433ACA006C2A1B /* NotificationHandler.swift in Sources */,
9B8285491CE20DE40027D15C /* HMScannerBorder.m in Sources */,
9B76EEB71C90740C002BF5D1 /* RuleSetsSelectionViewController.swift in Sources */,
B83AA5741D38E728007905B4 /* SegmentPageVC.swift in Sources */,
Expand Down Expand Up @@ -3449,10 +3453,10 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -3481,10 +3485,10 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -3513,11 +3517,11 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = PotatsoBase/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -3540,10 +3544,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = PotatsoBase/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -3566,11 +3570,11 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -3599,10 +3603,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -3629,11 +3633,11 @@
CLANG_ANALYZER_NONNULL = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -3670,10 +3674,10 @@
CLANG_ANALYZER_NONNULL = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 108;
CURRENT_PROJECT_VERSION = 110;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 108;
DYLIB_CURRENT_VERSION = 110;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down
2 changes: 1 addition & 1 deletion Potatso/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>108</string>
<string>110</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
12 changes: 8 additions & 4 deletions Potatso/More/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,18 @@ class SettingsViewController: FormViewController, MFMailComposeViewControllerDel
]
let rulesets = Manager.sharedManager.defaultConfigGroup.ruleSets.map({ $0.name }).joinWithSeparator(", ")
let defaultToProxy = Manager.sharedManager.defaultConfigGroup.defaultToProxy
var tags: [String] = []
if AppEnv.isTestFlight {
tags.append("testflight")
} else if AppEnv.isAppStore {
tags.append("store")
}
HelpshiftSupport.setMetadataBlock { () -> [NSObject : AnyObject]! in
return [
"Full Version": AppEnv.fullVersion,
"Default To Proxy": defaultToProxy,
"Default To Proxy": defaultToProxy ? "true": "false",
"Rulesets": rulesets,
HelpshiftSupportTagsKey: [
"testflight"
]
HelpshiftSupportTagsKey: tags
]
}
HelpshiftSupport.showConversation(self, withOptions: options)
Expand Down
65 changes: 65 additions & 0 deletions Potatso/NotificationHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// NotificationHandler.swift
// Potatso
//
// Created by LEI on 7/23/16.
// Copyright © 2016 TouchingApp. All rights reserved.
//

import Foundation
import ICSMainFramework

class NotificationHandler: NSObject, AppLifeCycleProtocol {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
configPush()
if let launchOptions = launchOptions, userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject: AnyObject], origin = userInfo["origin"] as? String {
if origin == "helpshift" {
if let rootVC = application.keyWindow?.rootViewController {
HelpshiftCore.handleRemoteNotification(userInfo, withController: rootVC)
}
}
}
return true
}

func configPush() {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Alert, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
}

func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("didRegisterForRemoteNotificationsWithDeviceToken: \(deviceToken.hexString())")
HelpshiftCore.registerDeviceToken(deviceToken)
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if let origin = userInfo["origin"] as? String {
if origin == "helpshift" {
if let rootVC = application.keyWindow?.rootViewController {
HelpshiftCore.handleRemoteNotification(userInfo, withController: rootVC)
}
completionHandler(.NewData)
return
}
}
completionHandler(.NoData)
}

}

extension NSData {
func hexString() -> String {
// "Array" of all bytes:
let bytes = UnsafeBufferPointer<UInt8>(start: UnsafePointer(self.bytes), count:self.length)
// Array of hex strings, one for each byte:
let hexBytes = bytes.map { String(format: "%02hhx", $0) }
// Concatenate all hex strings:
return hexBytes.joinWithSeparator("")
}
}
37 changes: 31 additions & 6 deletions Potatso/Utils/Receipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,47 @@
//

import Foundation
import ICSMainFramework
import KeychainAccess

class Receipt: NSObject, SKRequestDelegate {

static let shared = Receipt()

private let keychain = Keychain(service: "com.touchingapp.potatso")

private override init() {}

func validate() {
#if !DEBUG
// logEvent(.ReceiptValidation, attributes: nil)
// guard let receiptPath = NSBundle.mainBundle().appStoreReceiptURL?.path where NSFileManager.defaultManager().fileExistsAtPath(receiptPath) else {
if AppEnv.isTestFlight {
// if !validateKeychainAppStore() {
// failAndTerminate()
// return
// }
// validateReceipt(receiptPath, tryAgain: true)
#endif
} else if AppEnv.isAppStore {
if isStoreReceiptValidate() {
markKeychainAppStore()
} else {
failAndTerminate()
}
}
}

private func markKeychainAppStore() {
keychain["appstore"] = "true"
}

private func validateKeychainAppStore() -> Bool {
if let value = keychain["appstore"] {
return value == "true"
}
return false
}

private func isStoreReceiptValidate() -> Bool {
guard let receiptPath = NSBundle.mainBundle().appStoreReceiptURL?.path where NSFileManager.defaultManager().fileExistsAtPath(receiptPath) else {
return false
}
return ReceiptUtils.verifyReceiptAtPath(receiptPath)
}

private func requestNewReceipt() {
Expand Down
Loading

0 comments on commit cd12a0b

Please sign in to comment.