Skip to content

Commit

Permalink
Fixed #7: Added Parse Support
Browse files Browse the repository at this point in the history
  • Loading branch information
David Gatti committed Jun 17, 2015
1 parent 096a3d2 commit ad18471
Show file tree
Hide file tree
Showing 54 changed files with 7,584 additions and 123 deletions.
86 changes: 85 additions & 1 deletion GarageOpener.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
E59B08FA1B24E539009B50D4 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E59B08F91B24E539009B50D4 /* MainViewController.swift */; };
E5D36DF41B24FE19004B675F /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E5D36DF31B24FE19004B675F /* Settings.bundle */; };
E5D36DF61B2644A9004B675F /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5D36DF51B2644A9004B675F /* AppSettings.swift */; };
E5DB28C61B2DFE6600B3C093 /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28C51B2DFE6600B3C093 /* Bolts.framework */; };
E5DB28C81B2DFE7100B3C093 /* Parse.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28C71B2DFE7100B3C093 /* Parse.framework */; };
E5DB28CA1B2DFF2000B3C093 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28C91B2DFF2000B3C093 /* AudioToolbox.framework */; };
E5DB28CC1B2DFF2900B3C093 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28CB1B2DFF2900B3C093 /* CFNetwork.framework */; };
E5DB28CE1B2DFF4E00B3C093 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28CD1B2DFF4E00B3C093 /* CoreGraphics.framework */; };
E5DB28D01B2DFF5800B3C093 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28CF1B2DFF5800B3C093 /* CoreLocation.framework */; };
E5DB28D21B2DFF6100B3C093 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28D11B2DFF6100B3C093 /* MobileCoreServices.framework */; };
E5DB28D41B2DFF6900B3C093 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28D31B2DFF6900B3C093 /* QuartzCore.framework */; };
E5DB28D61B2DFF7100B3C093 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28D51B2DFF7100B3C093 /* Security.framework */; };
E5DB28D81B2DFF7700B3C093 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28D71B2DFF7700B3C093 /* StoreKit.framework */; };
E5DB28DA1B2DFF8000B3C093 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28D91B2DFF8000B3C093 /* SystemConfiguration.framework */; };
E5DB28DC1B2DFF8C00B3C093 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28DB1B2DFF8C00B3C093 /* libz.dylib */; };
E5DB28DE1B2DFFA000B3C093 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28DD1B2DFFA000B3C093 /* libsqlite3.dylib */; };
E5DB28E01B2DFFA800B3C093 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28DF1B2DFFA800B3C093 /* Accounts.framework */; };
E5DB28E21B2DFFAE00B3C093 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DB28E11B2DFFAE00B3C093 /* Social.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -52,13 +67,43 @@
E59B08F91B24E539009B50D4 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
E5D36DF31B24FE19004B675F /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
E5D36DF51B2644A9004B675F /* AppSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = "<group>"; };
E5DB28C51B2DFE6600B3C093 /* Bolts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Bolts.framework; sourceTree = "<group>"; };
E5DB28C71B2DFE7100B3C093 /* Parse.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Parse.framework; sourceTree = "<group>"; };
E5DB28C91B2DFF2000B3C093 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
E5DB28CB1B2DFF2900B3C093 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
E5DB28CD1B2DFF4E00B3C093 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
E5DB28CF1B2DFF5800B3C093 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
E5DB28D11B2DFF6100B3C093 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
E5DB28D31B2DFF6900B3C093 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
E5DB28D51B2DFF7100B3C093 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
E5DB28D71B2DFF7700B3C093 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
E5DB28D91B2DFF8000B3C093 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
E5DB28DB1B2DFF8C00B3C093 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
E5DB28DD1B2DFFA000B3C093 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
E5DB28DF1B2DFFA800B3C093 /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
E5DB28E11B2DFFAE00B3C093 /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
E59B08C01B22974F009B50D4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E5DB28E21B2DFFAE00B3C093 /* Social.framework in Frameworks */,
E5DB28E01B2DFFA800B3C093 /* Accounts.framework in Frameworks */,
E5DB28DE1B2DFFA000B3C093 /* libsqlite3.dylib in Frameworks */,
E5DB28DC1B2DFF8C00B3C093 /* libz.dylib in Frameworks */,
E5DB28DA1B2DFF8000B3C093 /* SystemConfiguration.framework in Frameworks */,
E5DB28D81B2DFF7700B3C093 /* StoreKit.framework in Frameworks */,
E5DB28D61B2DFF7100B3C093 /* Security.framework in Frameworks */,
E5DB28D41B2DFF6900B3C093 /* QuartzCore.framework in Frameworks */,
E5DB28D21B2DFF6100B3C093 /* MobileCoreServices.framework in Frameworks */,
E5DB28D01B2DFF5800B3C093 /* CoreLocation.framework in Frameworks */,
E5DB28CE1B2DFF4E00B3C093 /* CoreGraphics.framework in Frameworks */,
E5DB28CC1B2DFF2900B3C093 /* CFNetwork.framework in Frameworks */,
E5DB28CA1B2DFF2000B3C093 /* AudioToolbox.framework in Frameworks */,
E5DB28C81B2DFE7100B3C093 /* Parse.framework in Frameworks */,
E5DB28C61B2DFE6600B3C093 /* Bolts.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -93,8 +138,8 @@
E59B08C51B22974F009B50D4 /* GarageOpener */ = {
isa = PBXGroup;
children = (
E59B08C81B22974F009B50D4 /* AppDelegate.swift */,
E55C85B71B2CAF090063B75E /* NewAccount.swift */,
E59B08C81B22974F009B50D4 /* AppDelegate.swift */,
E59B08CD1B22974F009B50D4 /* ViewController.swift */,
E59B08F91B24E539009B50D4 /* MainViewController.swift */,
E59B08F31B23FA6F009B50D4 /* Http.swift */,
Expand All @@ -108,6 +153,8 @@
E59B08C61B22974F009B50D4 /* Supporting Files */ = {
isa = PBXGroup;
children = (
E5DB28E41B30EE4E00B3C093 /* ParseSDK */,
E5DB28E31B30EE1900B3C093 /* Frameworks */,
E5D36DF31B24FE19004B675F /* Settings.bundle */,
E59B08D21B22974F009B50D4 /* Images.xcassets */,
E59B08F51B24B94B009B50D4 /* SwiftJSON.swift */,
Expand Down Expand Up @@ -136,6 +183,35 @@
name = "Supporting Files";
sourceTree = "<group>";
};
E5DB28E31B30EE1900B3C093 /* Frameworks */ = {
isa = PBXGroup;
children = (
E5DB28E11B2DFFAE00B3C093 /* Social.framework */,
E5DB28DF1B2DFFA800B3C093 /* Accounts.framework */,
E5DB28DD1B2DFFA000B3C093 /* libsqlite3.dylib */,
E5DB28DB1B2DFF8C00B3C093 /* libz.dylib */,
E5DB28D91B2DFF8000B3C093 /* SystemConfiguration.framework */,
E5DB28D71B2DFF7700B3C093 /* StoreKit.framework */,
E5DB28D51B2DFF7100B3C093 /* Security.framework */,
E5DB28D31B2DFF6900B3C093 /* QuartzCore.framework */,
E5DB28D11B2DFF6100B3C093 /* MobileCoreServices.framework */,
E5DB28CF1B2DFF5800B3C093 /* CoreLocation.framework */,
E5DB28CD1B2DFF4E00B3C093 /* CoreGraphics.framework */,
E5DB28CB1B2DFF2900B3C093 /* CFNetwork.framework */,
E5DB28C91B2DFF2000B3C093 /* AudioToolbox.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
E5DB28E41B30EE4E00B3C093 /* ParseSDK */ = {
isa = PBXGroup;
children = (
E5DB28C51B2DFE6600B3C093 /* Bolts.framework */,
E5DB28C71B2DFE7100B3C093 /* Parse.framework */,
);
name = ParseSDK;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -377,6 +453,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/GarageOpener",
);
INFOPLIST_FILE = GarageOpener/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -391,6 +471,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/GarageOpener",
);
INFOPLIST_FILE = GarageOpener/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
16 changes: 16 additions & 0 deletions GarageOpener/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import UIKit
import CoreData
import Parse
import Bolts

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -17,6 +19,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

var settings = AppSettings.sharedInstance

// [Optional] Power your app with Local Datastore. For more info, go to
// https://parse.com/docs/ios_guide#localdatastore/iOS
Parse.enableLocalDatastore()

// Initialize Parse.
Parse.setApplicationId(settings.ParseAppID,
clientKey: settings.ParseClientKey)

// [Optional] Track statistics around application opens.
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)

return true
}

Expand Down
142 changes: 134 additions & 8 deletions GarageOpener/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,158 @@
//

import Foundation

import Parse

class AppSettings {

//MARK: Static
static let sharedInstance = AppSettings()

//MARK: Variables
var isOpen: Int = 0
var useCount: Int = 0
var lastUser: String = ""
var token: String = ""
var deviceID: String = ""
var lastUsed: NSDate = NSDate.distantPast() as! NSDate
var userID: String = ""

//MARK: Secrets
var ParticleToken: String = ""
var ParticleDeviceID: String = ""
var ParseAppID: String = ""
var ParseClientKey: String = ""

//MARK: Initialization
init() {

let defaults = NSUserDefaults.standardUserDefaults()
self.userID = defaults.stringForKey("userID")!

// Get the Token and Device ID for Particle
var myDict: NSDictionary?

if let path = NSBundle.mainBundle().pathForResource("Secrets", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}

if let tmpToken = myDict?.objectForKey("token") as? String {
self.token = tmpToken
// Particle.io
if let tmpParseToken = myDict?.objectForKey("ParticleToken") as? String {
self.ParticleToken = tmpParseToken
}

if let tmpParseDeviceID = myDict?.objectForKey("ParticleDeviceID") as? String {
self.ParticleDeviceID = tmpParseDeviceID
}

// Parse.com
if let tmpParseAppID = myDict?.objectForKey("ParseAppID") as? String {
self.ParseAppID = tmpParseAppID
}

if let tmpParseClientID = myDict?.objectForKey("ParseClientID") as? String {
self.ParseClientKey = tmpParseClientID
}
}

//MARK: Get

func get(completition:() -> ()) {

println("get")

var count: Int = 0

getLastUser { (result) -> Void in
println("GetLastUser - result")
count++
}

getUseCount { (result) -> Void in
println("GetUserCount - result")
count++
}

while true {
if count == 2 {
return completition()
}
}
}

private func getLastUser(completition:() -> ()) {
println("GetLastUser - Header")

var qHistory = PFQuery(className: "History")
qHistory.orderByDescending("createdAt")
qHistory.getFirstObjectInBackgroundWithBlock { (lastEntry: PFObject?, error) -> Void in

println("GetLastUser - qHistory")

var qUser = PFQuery(className: "Users")

qUser.getObjectInBackgroundWithId((lastEntry?.objectForKey("userID") as? String)!) {
(name: PFObject?, error) -> Void in

println("GetLastUser - qUser")

self.lastUser = (name?.objectForKey("name") as? String)!

self.getLastUsed(name!.createdAt!, completition: { () -> () in

return completition()
})


}
}

if let tmpDeviceID = myDict?.objectForKey("deviceID") as? String {
self.deviceID = tmpDeviceID
println("GetLastUser - Footer")



}

private func getUseCount(completition:() -> ()) {
println("GetUserCount - Header")

var qGarageDoor = PFQuery(className:"GarageDoor")
qGarageDoor.getObjectInBackgroundWithId("eX9QCJGga5") { (garage: PFObject?, error: NSError?) -> Void in
self.useCount = (garage!.objectForKey("useCount") as! Int)
return completition()
}


}

private func getLastUsed(time: NSDate, completition:() -> ()) {
println("GetLastUsed - Header")

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.zzz'Z'"

//var date:NSDate = dateFormatter.dateFromString(time)!
self.lastUsed = time

return completition()
}

//MARK: Set

func set(completition: (result: String) -> Void) {
setHistory { (result) -> Void in }
setGarageDoor { (result) -> Void in }
}

private func setHistory(completition: (result: String) -> Void) {
let history = PFObject(className: "History")
history["userID"] = self.userID
history["object"] = 1
history["state"] = self.isOpen
history.saveInBackground()
}

private func setGarageDoor(completition: (result: String) -> Void) {
var query = PFObject(withoutDataWithClassName: "GarageDoor", objectId: "eX9QCJGga5")
query["useCount"] = self.useCount
query.saveInBackground()
}
}
Binary file added GarageOpener/Bolts.framework/Bolts
Binary file not shown.
49 changes: 49 additions & 0 deletions GarageOpener/Bolts.framework/Headers/BFAppLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#import <Foundation/Foundation.h>

/*! The version of the App Link protocol that this library supports */
FOUNDATION_EXPORT NSString *const BFAppLinkVersion;

/*!
Contains App Link metadata relevant for navigation on this device
derived from the HTML at a given URL.
*/
@interface BFAppLink : NSObject

/*!
Creates a BFAppLink with the given list of BFAppLinkTargets and target URL.
Generally, this will only be used by implementers of the BFAppLinkResolving protocol,
as these implementers will produce App Link metadata for a given URL.
@param sourceURL the URL from which this App Link is derived
@param targets an ordered list of BFAppLinkTargets for this platform derived
from App Link metadata.
@param webURL the fallback web URL, if any, for the app link.
*/
+ (instancetype)appLinkWithSourceURL:(NSURL *)sourceURL
targets:(NSArray *)targets
webURL:(NSURL *)webURL;

/*! The URL from which this BFAppLink was derived */
@property (nonatomic, strong, readonly) NSURL *sourceURL;

/*!
The ordered list of targets applicable to this platform that will be used
for navigation.
*/
@property (nonatomic, copy, readonly) NSArray *targets;

/*! The fallback web URL to use if no targets are installed on this device. */
@property (nonatomic, strong, readonly) NSURL *webURL;

@end
Loading

0 comments on commit ad18471

Please sign in to comment.