Skip to content

Commit

Permalink
Add Watchkit support (close #465)
Browse files Browse the repository at this point in the history
PR #478

* Adds WatchKit support via CocoaPods (#465)

* Fixes missing file for watchOS

* Change watchOS product name

* Adds modual map for watchos

* Adds carthage watch example

* Adds cocoapods watch example

* Update CocoaPods demo to include older watchOS version

I noticed that apps using this library could not launch on older watchOS version. This adds a demo project to reproduce this,

* Fix crash on < watchOS 6

This fixes the crash mentioned in the prev. commit. It removes the frameworks for watchOS from the Podspec.

* Changed button name

* Update podspec for watchOS target

Updated podspec excluding the new Reachability feature added when we got rid of the third part dependency Reachability.swift

* Update travis scripts

* Pod update

Co-authored-by: leoAsana <56038088+leoAsana@users.noreply.github.com>
  • Loading branch information
AlexBenny and leoAsana committed Jan 14, 2020
1 parent 461d12c commit 59212f4
Show file tree
Hide file tree
Showing 120 changed files with 4,357 additions and 855 deletions.
26 changes: 13 additions & 13 deletions .travis.yml
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode11.2
osx_image: xcode11.3

env:
global:
Expand All @@ -10,21 +10,21 @@ before_install: . .travis/setup.sh

jobs:
include:
- name: "Test Snowplow framework [iOS]"
script: .travis/test_framework.sh "${BUILD_DEST}" "${BUILD_PROJECT_LIB}" "${BUILD_SCHEME_LIB}"
- name: "Test Snowplow framework"
script: .travis/test_framework.sh "${BUILD_PROJECT_LIB}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_LIB_IOS}" "${BUILD_DEST_WATCH}" "${BUILD_SCHEME_LIB_WATCH}"
after_success: slather

- name: "Test Snowplow ObjC demo app [iOS]"
script: .travis/test_ios_demo.sh SnowplowDemo Podfile "${BUILD_DEST}" "${BUILD_WORKSPACE_OBJC_DEMO}" "${BUILD_SCHEME_OBJC_DEMO}"
- name: "Test Snowplow ObjC demo app"
script: .travis/test_ios_demo.sh SnowplowDemo Podfile "${BUILD_WORKSPACE_OBJC_DEMO}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_OBJC_DEMO}"

- name: "Test Snowplow Swift demo app [iOS] using Carthage"
script: .travis/test_ios_demo.sh SnowplowSwiftCarthageDemo Cartfile "${BUILD_DEST}" "${BUILD_PROJECT_SWIFT_DEMO}" "${BUILD_SCHEME_SWIFT_DEMO}"
- name: "Test Snowplow Swift demo app using Carthage"
script: .travis/test_ios_demo.sh SnowplowSwiftCarthageDemo Cartfile "${BUILD_PROJECT_SWIFT_DEMO}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_SWIFT_DEMO_IOS}"

- name: "Test Snowplow Swift demo app [iOS] using Cocoapods (no directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_simple "${BUILD_DEST}" "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_SCHEME_SWIFT_DEMO}"
- name: "Test Snowplow Swift demo app using Cocoapods (no directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_simple "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_SWIFT_DEMO_IOS}" "${BUILD_DEST_PAIRED}" "${BUILD_SCHEME_SWIFT_DEMO_WATCH}"

- name: "Test Snowplow Swift demo app [iOS] using Cocoapods (use_frameworks! directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_frameworks "${BUILD_DEST}" "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_SCHEME_SWIFT_DEMO}"
- name: "Test Snowplow Swift demo app using Cocoapods (use_frameworks! directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_frameworks "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_SWIFT_DEMO_IOS}" "${BUILD_DEST_PAIRED}" "${BUILD_SCHEME_SWIFT_DEMO_WATCH}"

- name: "Test Snowplow Swift demo app [iOS] using Cocoapods (use_modular_headers! directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_modular_headers "${BUILD_DEST}" "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_SCHEME_SWIFT_DEMO}"
- name: "Test Snowplow Swift demo app using Cocoapods (use_modular_headers! directive)"
script: .travis/test_ios_demo.sh SnowplowSwiftCocoapodsDemo Podfile_modular_headers "${BUILD_WORKSPACE_SWIFT_DEMO}" "${BUILD_DEST_IOS}" "${BUILD_SCHEME_SWIFT_DEMO_IOS}" "${BUILD_DEST_PAIRED}" "${BUILD_SCHEME_SWIFT_DEMO_WATCH}"
7 changes: 6 additions & 1 deletion .travis/Podfile_frameworks
@@ -1,9 +1,14 @@
platform :ios, '9.0'
use_frameworks!

workspace 'SnowplowSwiftDemo.xcworkspace'

target 'SnowplowSwiftDemo' do
platform :ios, '9.0'
pod 'SnowplowTracker', :path=> '../../'
end

target 'SnowplowSwiftWatch Extension' do
platform :watchos, '4.0'
pod 'SnowplowTracker', :path=> '../../'
end

9 changes: 7 additions & 2 deletions .travis/Podfile_modular_headers
@@ -1,9 +1,14 @@
platform :ios, '9.0'
use_modular_headers!

workspace 'SnowplowSwiftDemo.xcworkspace'

target 'SnowplowSwiftDemo' do
platform :ios, '9.0'
pod 'SnowplowTracker', :path=> '../../'
end

target 'SnowplowSwiftWatch Extension' do
platform :watchos, '4.0'
pod 'SnowplowTracker', :path=> '../../'
end

10 changes: 8 additions & 2 deletions .travis/Podfile_simple
@@ -1,8 +1,14 @@
platform :ios, '9.0'


workspace 'SnowplowSwiftDemo.xcworkspace'

target 'SnowplowSwiftDemo' do
platform :ios, '9.0'
pod 'SnowplowTracker', :path=> '../../'
end

target 'SnowplowSwiftWatch Extension' do
platform :watchos, '4.0'
pod 'SnowplowTracker', :path=> '../../'
end


15 changes: 12 additions & 3 deletions .travis/setup.sh
Expand Up @@ -12,11 +12,20 @@ if [ "$CI" = true ]; then
fi

printf "\n\n Setup env variables \n"
BUILD_DEST="platform=iOS Simulator,OS=13.2.2,name=iPhone 8"

BUILD_DEST_IOS="platform=iOS Simulator,OS=13.3,name=iPhone 11 Pro"
BUILD_DEST_PAIRED="platform=iOS Simulator,OS=13.3,name=iPhone 11 Pro"
BUILD_DEST_WATCH="platform=watchOS Simulator,OS=6.1.1,name=Apple Watch Series 5 - 44mm"

BUILD_PROJECT_LIB="-project Snowplow.xcodeproj"
BUILD_SCHEME_LIB="-scheme Snowplow-iOS"
BUILD_SCHEME_LIB_IOS="-scheme Snowplow-iOS"
BUILD_SCHEME_LIB_WATCH="-scheme Snowplow-watchOS"

BUILD_WORKSPACE_OBJC_DEMO="-workspace SnowplowDemo.xcworkspace"
BUILD_SCHEME_OBJC_DEMO="-scheme SnowplowDemo"

BUILD_WORKSPACE_SWIFT_DEMO="-workspace SnowplowSwiftDemo.xcworkspace"
BUILD_PROJECT_SWIFT_DEMO="-project SnowplowSwiftDemo.xcodeproj"
BUILD_SCHEME_SWIFT_DEMO="-scheme SnowplowSwiftDemo"
BUILD_SCHEME_SWIFT_DEMO_IOS="-scheme SnowplowSwiftDemo"
BUILD_SCHEME_SWIFT_DEMO_WATCH="-scheme SnowplowSwiftWatch"

17 changes: 11 additions & 6 deletions .travis/test_framework.sh
@@ -1,11 +1,16 @@
#!/usr/bin/env bash

DEST=$1
PROJECT=$2
SCHEME=$3
PROJECT=$1
DEST_IOS=$2
SCHEME_IOS=$3
DEST_WATCH=$4
SCHEME_WATCH=$5

printf "\n\n Carthage bootstrap \n"
carthage bootstrap --platform iOS
carthage bootstrap

printf "\n\n Test framework \n"
set -o pipefail && xcodebuild -sdk iphonesimulator -destination "${DEST}" ${PROJECT} ${SCHEME} clean test | xcpretty
printf "\n\n Test framework on iOS \n"
set -o pipefail && xcodebuild -destination "${DEST_IOS}" ${PROJECT} ${SCHEME_IOS} clean test | xcpretty

printf "\n\n Build framework on watchOS \n"
set -o pipefail && xcodebuild -destination "${DEST_WATCH}" ${PROJECT} ${SCHEME_WATCH} clean build | xcpretty
19 changes: 13 additions & 6 deletions .travis/test_ios_demo.sh
Expand Up @@ -2,15 +2,17 @@

APP=$1
DEP_FILE=$2
DEST=$3
PROJECT=$4
SCHEME=$5
PROJECT=$3
DEST_IOS=$4
SCHEME_IOS=$5
DEST_WATCH=$6
SCHEME_WATCH=$7

if [ $DEP_FILE == "Cartfile" ]; then
printf "\n\n Carthage update \n"
cd Examples/$APP
./generateCartfile.sh
carthage update --platform ios
carthage update
elif [ $DEP_FILE == "Podfile" ]; then
printf "\n\n Pod update \n"
cd Examples/$APP
Expand All @@ -25,5 +27,10 @@ else
exit 1
fi

printf "\n\n Test ${APP} \n"
set -o pipefail && xcodebuild -sdk iphonesimulator -destination "${DEST}" ${PROJECT} ${SCHEME} clean build | xcpretty
printf "\n\n Build iOS ${APP} \n"
set -o pipefail && xcodebuild -destination "${DEST_IOS}" ${PROJECT} ${SCHEME_IOS} clean build | xcpretty

if [ ! -z "$SCHEME_WATCH" ]; then
printf "\n\n Build watchOS ${APP} \n"
set -o pipefail && xcodebuild -destination "${DEST_WATCH}" ${PROJECT} ${SCHEME_WATCH} clean build | xcpretty
fi
25 changes: 25 additions & 0 deletions Examples/CommonSwiftCode/ExtensionDelegate.swift
@@ -0,0 +1,25 @@
//
// ExtensionDelegate.swift
// SnowplowSwiftDemoWatch WatchKit Extension
//
// Created by Leo Mehlig on 12.11.19.
// Copyright © 2019 snowplowanalytics. All rights reserved.
//

import WatchKit

class ExtensionDelegate: NSObject, WKExtensionDelegate {

func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
}

func applicationDidBecomeActive() {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillResignActive() {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, etc.
}
}
80 changes: 80 additions & 0 deletions Examples/CommonSwiftCode/InterfaceController.swift
@@ -0,0 +1,80 @@
//
// InterfaceController.swift
// SnowplowSwiftDemoWatch WatchKit Extension
//
// Created by Leo Mehlig on 12.11.19.
// Copyright © 2019 snowplowanalytics. All rights reserved.
//

import WatchKit
import Foundation
import SnowplowTracker

class InterfaceController: WKInterfaceController, SPRequestCallback {

let kAppId = "DemoAppId"
let kNamespace = "DemoAppNamespace"

func getTracker(_ url: String, method: SPRequestOptions, protocol _protocol: SPProtocol) -> SPTracker {
let emitter = SPEmitter.build({ (builder : SPEmitterBuilder?) -> Void in
builder!.setUrlEndpoint(url)
builder!.setHttpMethod(method)
builder!.setProtocol(_protocol)
builder!.setCallback(self)
builder!.setEmitRange(500)
builder!.setEmitThreadPoolSize(20)
builder!.setByteLimitPost(52000)
})
let subject = SPSubject(platformContext: true, andGeoContext: false)
let newTracker = SPTracker.build({ (builder : SPTrackerBuilder?) -> Void in
builder!.setEmitter(emitter)
builder!.setAppId(self.kAppId)
builder!.setTrackerNamespace(self.kNamespace)
builder!.setBase64Encoded(false)
builder!.setSessionContext(true)
builder!.setSubject(subject)
builder!.setLifecycleEvents(true)
builder!.setAutotrackScreenViews(true)
builder!.setScreenContext(true)
builder!.setApplicationContext(true)
builder!.setExceptionEvents(true)
builder!.setInstallEvent(true)
})
return newTracker!
}

var tracker : SPTracker!


override func awake(withContext context: Any?) {
super.awake(withContext: context)
self.tracker = self.getTracker("acme.fake.com", method: .get, protocol: .http)
// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

@IBAction func sendEvent() {
DispatchQueue.global(qos: .default).async {
// Track all types of events
DemoUtils.trackAll(self.tracker)
}
}

func onSuccess(withCount successCount: Int) {
print("Success: \(successCount)")
}

func onFailure(withCount failureCount: Int, successCount: Int) {
print("Failure: \(failureCount), Success: \(successCount)")
}

}
4 changes: 2 additions & 2 deletions Examples/SnowplowDemo/Podfile.lock
Expand Up @@ -2,7 +2,7 @@ PODS:
- FMDB (2.6.2):
- FMDB/standard (= 2.6.2)
- FMDB/standard (2.6.2)
- SnowplowTracker (1.1.5):
- SnowplowTracker (1.2.0-M3):
- FMDB (~> 2.6.2)

DEPENDENCIES:
Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
FMDB: 854a0341b4726e53276f2a8996f06f1b80f9259a
SnowplowTracker: 51baa293052bd96d2326cb779e86ef1c8015942b
SnowplowTracker: 2ea78776f9f624eccf5e026db87bd915785f894e

PODFILE CHECKSUM: 375b0f24567595e0cac8c9289ed3aea84854fdd6

Expand Down

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

4 changes: 2 additions & 2 deletions Examples/SnowplowDemo/Pods/Manifest.lock

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

0 comments on commit 59212f4

Please sign in to comment.