Skip to content

Instantly share code, notes, and snippets.

View mobilequickie's full-sized avatar

Mobile Quickie mobilequickie

View GitHub Profile
@mobilequickie
mobilequickie / AppDelegate.swift
Created August 31, 2018 23:04
AnalyticsService
var analyticsService: AnalyticsService?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Initialize the analytics service
analyticsService = LocalAnalyticsService()
return true
}
@mobilequickie
mobilequickie / MasterViewController.swift
Last active September 8, 2018 07:05
MasterViewController
class MasterViewController: UITableViewController {
var analyticsService: AnalyticsService? = nil
override func viewDidLoad() {
super.viewDidLOad()
analyticsService = (UIApplication.shared.delegate as! AppDelegate).analyticsService
self.analyticsService?.recordEvent("loaded", parameters: ["op":"viewDidLoad"], metrics: nil)
}
@mobilequickie
mobilequickie / AnalyticsService.swift
Created August 31, 2018 23:10
AnalyticsService Protocol
protocol AnalyticsService {
func recordEvent(_ eventName: String, parameters: [String:String]?, metrics: [String:Double]?) -> Void
}
@mobilequickie
mobilequickie / LocalAnalyticsService.swift
Created August 31, 2018 23:13
AnalyticsService Local
import Foundation
class LocalAnalyticsService : AnalyticsService {
init() {
print("LocalAnalyticsService: session-start")
}
func recordEvent(_ eventName: String, parameters: [String : String]?, metrics: [String : Double]?) {
var event = ""
if (parameters != nil) {
@mobilequickie
mobilequickie / Podfile
Created August 31, 2018 23:17
Podfile
target 'MyNotes' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Analytics dependency
pod 'AWSPinpoint'
end
@mobilequickie
mobilequickie / AWSAnalyticsService.swift
Created August 31, 2018 23:19
AnalyticsService AWS
import Foundation
import AWSCore
import AWSPinpoint
class AWSAnalyticsService : AnalyticsService {
var pinpoint: AWSPinpoint?
init() {
let config = AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: nil)
pinpoint = AWSPinpoint(configuration: config)
@mobilequickie
mobilequickie / DeviceUtility.swift
Last active March 14, 2022 20:37
Utility for deciphering iOS device names from identifier
// Updated April 8 for iPad Mini 5th gen, iPad Air 3rd gen, and all Apple Watch to gen 4.
// Updated Oct 9 for iPhone XS, iPhone XS Max, and iPhone XR
// Call this from any class that needs it: let modelName = UIDevice.current.modelName
// More here: https://gist.github.com/adamawolf/3048717
// Source of internal names came from this wiki: https://www.theiphonewiki.com/wiki/
import UIKit
public extension UIDevice {
@mobilequickie
mobilequickie / recordCustomProfileDemographics.swift
Created September 6, 2018 23:16
Function inside of AWSAnalyticsService class that updates custom attributes for collecting demographics in Amazon Pinpoint
// Send custom model and platformVersion for this device to Amazon Pinpoint
func recordCustomProfileDemographics() {
let profile: AWSPinpointEndpointProfile = (pinpoint?.targetingClient.currentEndpointProfile())!
// Call our DeviceUtility class for readable Apple model type and iOS version for this device
profile.demographic?.model = UIDevice.current.modelName
profile.demographic?.platformVersion = UIDevice.current.systemVersion
pinpoint?.targetingClient.update(profile)
}
@mobilequickie
mobilequickie / endpointrequest.json
Last active September 20, 2018 17:37
Pinpoint EndpointRequest
{
"ChannelType": "SMS",
"Address": "+12065551212",
"Demographic": {
"AppVersion": "1.0",
"Make": "apple",
"Model": "iPhone",
"ModelVersion": "iPhone X",
"Platform": "ios",
"PlatformVersion": "12.0",
//Get the Amazon Pinpoint EndpointId from the device
let profile: AWSPinpointEndpointProfile = (pinpoint?.targetingClient.currentEndpointProfile())!
print("EndpointId: \(profile.endpointId)")