Skip to content

Commit

Permalink
tvOS Support
Browse files Browse the repository at this point in the history
  • Loading branch information
yarneo committed Jun 16, 2016
1 parent 998b9fb commit 19520e6
Show file tree
Hide file tree
Showing 40 changed files with 1,457 additions and 56 deletions.
543 changes: 533 additions & 10 deletions HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions HelloMixpanel/HelloMixpanelTests/HelloMixpanelTests.m
Expand Up @@ -320,6 +320,7 @@ - (void)testValidSuperProperties {
XCTAssertNoThrow([self.mixpanel registerSuperPropertiesOnce:p defaultValue:@"v"], @"property type should be allowed");
}

#if !defined(MIXPANEL_TVOS_EXTENSION)
- (void)testTrackLaunchOptions {
NSDictionary *launchOptions = @{ UIApplicationLaunchOptionsRemoteNotificationKey: @{
@"mp": @{
Expand All @@ -340,6 +341,7 @@ - (void)testTrackLaunchOptions {
XCTAssertEqualObjects(p[@"message_id"], @"the_message_id", @"message_id not equal");
XCTAssertEqualObjects(p[@"message_type"], @"push", @"type does not equal inapp");
}
#endif

- (void)testTrackPushNotification {
[self.mixpanel trackPushNotification:@{ @"mp": @{
Expand Down Expand Up @@ -575,8 +577,10 @@ - (void)testEventTiming {
XCTAssertNil(p[@"$duration"], @"Tracking the same event should require a second call to timeEvent.");
}

#if !defined(MIXPANEL_TVOS_EXTENSION)
- (void)testTelephonyInfoInitialized {
XCTAssertNotNil([self.mixpanel performSelector:@selector(telephonyInfo)], @"telephonyInfo wasn't initialized");
}
#endif

@end
21 changes: 21 additions & 0 deletions HelloMixpanel/HelloMixpanel_tvOS/AppDelegate.h
@@ -0,0 +1,21 @@
//
// AppDelegate.h
// tvOS_Example
//
// Created by Yarden Eitan on 5/31/16.
// Copyright © 2016 Mixpanel. All rights reserved.
//

#import <UIKit/UIKit.h>
@import Mixpanel;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) Mixpanel *mixpanel;
@property (strong, nonatomic, retain) NSDate *startTime;

@property (nonatomic) UIBackgroundTaskIdentifier bgTask;
@property (strong, nonatomic) UIWindow *window;


@end

63 changes: 63 additions & 0 deletions HelloMixpanel/HelloMixpanel_tvOS/AppDelegate.m
@@ -0,0 +1,63 @@
//
// AppDelegate.m
// tvOS_Example
//
// Created by Yarden Eitan on 5/31/16.
// Copyright © 2016 Mixpanel. All rights reserved.
//

@import Mixpanel;
#import "AppDelegate.h"

// IMPORTANT!!! replace with your api token from https://mixpanel.com/account/
#define MIXPANEL_TOKEN @"6e8cf49a783398b5768f24f105a95fb5"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.mixpanel = [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN launchOptions:nil];
self.mixpanel.flushInterval = 20; // defaults to 60 seconds

// Set some super properties, which will be added to every tracked event
[self.mixpanel registerSuperProperties:@{@"Plan": @"Premium"}];

// Name a user in Mixpanel Streams
self.mixpanel.nameTag = @"Walter Sobchak";

// Start timing the session, then we'll have a duration when the user leaves the app
[self.mixpanel timeEvent:@"Session"];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
[self.mixpanel track:@"Session"];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
self.bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"%@ background task %lu cut short", self, (unsigned long)self.bgTask);

[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

NSLog(@"%@ starting background task %lu", self, (unsigned long)self.bgTask);

// track some events and set some people properties
Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel registerSuperProperties:@{@"Background Super Property": @"Hi!"}];
[mixpanel track:@"Background Event"];
[mixpanel.people set:@"Entered Background" to:[NSDate date]];

NSLog(@"%@ ending background task %lu", self, (unsigned long)self.bgTask);
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});

NSLog(@"%@ dispatched background task %lu", self, (unsigned long)self.bgTask);
}

@end
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,17 @@
{
"layers" : [
{
"filename" : "Front.imagestacklayer"
},
{
"filename" : "Middle.imagestacklayer"
},
{
"filename" : "Back.imagestacklayer"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,17 @@
{
"layers" : [
{
"filename" : "Front.imagestacklayer"
},
{
"filename" : "Middle.imagestacklayer"
},
{
"filename" : "Back.imagestacklayer"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,26 @@
{
"assets" : [
{
"size" : "1280x768",
"idiom" : "tv",
"filename" : "App Icon - Large.imagestack",
"role" : "primary-app-icon"
},
{
"size" : "400x240",
"idiom" : "tv",
"filename" : "App Icon - Small.imagestack",
"role" : "primary-app-icon"
},
{
"size" : "1920x720",
"idiom" : "tv",
"filename" : "Top Shelf Image.imageset",
"role" : "top-shelf-image"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Icon-72.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Icon@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,15 @@
{
"images" : [
{
"orientation" : "landscape",
"idiom" : "tv",
"extent" : "full-screen",
"minimum-system-version" : "9.0",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

0 comments on commit 19520e6

Please sign in to comment.