├── .gitignore ├── README.md ├── app.js ├── config.js ├── ios-client ├── ApnsDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── segphault.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── segphault.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── ApnsDemo.xcscheme │ │ └── xcschememanagement.plist ├── ApnsDemo │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift └── ApnsDemoTests │ ├── ApnsDemoTests.swift │ └── Info.plist └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.pem 3 | node_modules 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rethinkdb-mobile-push 2 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require("express"); 2 | var bodyParser = require("body-parser"); 3 | var apn = require("apn"); 4 | var fs = require("fs"); 5 | var r = require("rethinkdb"); 6 | 7 | var config = require("./config"); 8 | 9 | var app = express(); 10 | app.use(bodyParser.json()); 11 | 12 | app.listen(config.port); 13 | console.log("Server started on port " + config.port); 14 | var apnConnection = new apn.Connection(config.apns); 15 | 16 | function findNearby(location) { 17 | return r.table("users").getIntersecting( 18 | r.circle(location, 100, {unit: "mi"}), {index: "place"}); 19 | } 20 | 21 | var conn; 22 | r.connect(config.db).then(function(c) { 23 | conn = c; 24 | return r.dbCreate(config.db.db).run(conn); 25 | }) 26 | .then(function() { 27 | return r.tableCreate("users").run(conn); 28 | }) 29 | .error(function(err) { 30 | if (err.msg.indexOf("already exists") == -1) 31 | console.log(err); 32 | }) 33 | .finally(function() { 34 | r.connect(config.db).then(function(conn) { 35 | return r.table("users").changes().run(conn); 36 | }) 37 | .then(function(change) { 38 | change.each(function(err, item) { 39 | if (!item.new_val) return; 40 | findNearby(item.new_val.place).run(conn).then(function(users) { 41 | users.each(function(err, user) { 42 | if (user.id === item.new_val.id) return; 43 | 44 | var note = new apn.Notification(); 45 | note.sound = "ping.aiff"; 46 | note.alert = "A user checked in nearby"; 47 | note.payload = item.new_val.place; 48 | 49 | apnConnection.pushNotification(note, new apn.Device(user.id)); 50 | }); 51 | }); 52 | }); 53 | }); 54 | }); 55 | 56 | app.get("/api/pins", function(req, res) { 57 | var place = req.query.place.split(","); 58 | 59 | r.connect(config.db).then(function(conn) { 60 | return findNearby([+place[1], +place[0]])("place").run(conn) 61 | .finally(function() { conn.close(); }); 62 | }) 63 | .then(function(cursor) { return cursor.toArray(); }) 64 | .then(function(output) { res.json(output); }); 65 | }); 66 | 67 | app.post("/api/checkin", function(req,res) { 68 | var token = req.body.token.replace(/[<> ]/g, ""); 69 | var place = r.point(req.body.place[1], req.body.place[0]); 70 | 71 | r.connect(config.db).then(function(conn) { 72 | return r.table("users").insert({id: token, place: place, time: r.now()}, 73 | {conflict: "update"}).run(conn) 74 | .finally(function() { conn.close(); }); 75 | }) 76 | .then(function(output) { 77 | res.json({success: true}); 78 | }); 79 | }); 80 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | db: { 3 | host: "localhost", 4 | port: 28015, 5 | db: "pushdemo" 6 | }, 7 | apns: { 8 | key: fs.readFileSync("key.pem"), 9 | cert: fs.readFileSync("cert.pem"), 10 | passphrase: "xxxxxxxxx", 11 | production: false 12 | }, 13 | port: 8099 14 | } 15 | 16 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 339538F71ADF2C270047B47B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 339538F61ADF2C270047B47B /* AppDelegate.swift */; }; 11 | 339538F91ADF2C270047B47B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 339538F81ADF2C270047B47B /* ViewController.swift */; }; 12 | 339538FC1ADF2C270047B47B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 339538FA1ADF2C270047B47B /* Main.storyboard */; }; 13 | 339538FE1ADF2C270047B47B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 339538FD1ADF2C270047B47B /* Images.xcassets */; }; 14 | 339539011ADF2C270047B47B /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 339538FF1ADF2C270047B47B /* LaunchScreen.xib */; }; 15 | 3395390D1ADF2C280047B47B /* ApnsDemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3395390C1ADF2C280047B47B /* ApnsDemoTests.swift */; }; 16 | 339539171AE04F480047B47B /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 339539161AE04F480047B47B /* CoreLocation.framework */; }; 17 | 339539191AE1E6B90047B47B /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 339539181AE1E6B90047B47B /* MapKit.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 339539071ADF2C280047B47B /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 339538E91ADF2C270047B47B /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 339538F01ADF2C270047B47B; 26 | remoteInfo = ApnsDemo; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 339538F11ADF2C270047B47B /* ApnsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ApnsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 339538F51ADF2C270047B47B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 339538F61ADF2C270047B47B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 34 | 339538F81ADF2C270047B47B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 35 | 339538FB1ADF2C270047B47B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 36 | 339538FD1ADF2C270047B47B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 37 | 339539001ADF2C270047B47B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 38 | 339539061ADF2C280047B47B /* ApnsDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ApnsDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 3395390B1ADF2C280047B47B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | 3395390C1ADF2C280047B47B /* ApnsDemoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApnsDemoTests.swift; sourceTree = ""; }; 41 | 339539161AE04F480047B47B /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 42 | 339539181AE1E6B90047B47B /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | 339538EE1ADF2C270047B47B /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | 339539191AE1E6B90047B47B /* MapKit.framework in Frameworks */, 51 | 339539171AE04F480047B47B /* CoreLocation.framework in Frameworks */, 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | 339539031ADF2C280047B47B /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | 339538E81ADF2C270047B47B = { 66 | isa = PBXGroup; 67 | children = ( 68 | 339539181AE1E6B90047B47B /* MapKit.framework */, 69 | 339539161AE04F480047B47B /* CoreLocation.framework */, 70 | 339538F31ADF2C270047B47B /* ApnsDemo */, 71 | 339539091ADF2C280047B47B /* ApnsDemoTests */, 72 | 339538F21ADF2C270047B47B /* Products */, 73 | ); 74 | sourceTree = ""; 75 | }; 76 | 339538F21ADF2C270047B47B /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 339538F11ADF2C270047B47B /* ApnsDemo.app */, 80 | 339539061ADF2C280047B47B /* ApnsDemoTests.xctest */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | 339538F31ADF2C270047B47B /* ApnsDemo */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 339538F61ADF2C270047B47B /* AppDelegate.swift */, 89 | 339538F81ADF2C270047B47B /* ViewController.swift */, 90 | 339538FA1ADF2C270047B47B /* Main.storyboard */, 91 | 339538FD1ADF2C270047B47B /* Images.xcassets */, 92 | 339538FF1ADF2C270047B47B /* LaunchScreen.xib */, 93 | 339538F41ADF2C270047B47B /* Supporting Files */, 94 | ); 95 | path = ApnsDemo; 96 | sourceTree = ""; 97 | }; 98 | 339538F41ADF2C270047B47B /* Supporting Files */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 339538F51ADF2C270047B47B /* Info.plist */, 102 | ); 103 | name = "Supporting Files"; 104 | sourceTree = ""; 105 | }; 106 | 339539091ADF2C280047B47B /* ApnsDemoTests */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 3395390C1ADF2C280047B47B /* ApnsDemoTests.swift */, 110 | 3395390A1ADF2C280047B47B /* Supporting Files */, 111 | ); 112 | path = ApnsDemoTests; 113 | sourceTree = ""; 114 | }; 115 | 3395390A1ADF2C280047B47B /* Supporting Files */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 3395390B1ADF2C280047B47B /* Info.plist */, 119 | ); 120 | name = "Supporting Files"; 121 | sourceTree = ""; 122 | }; 123 | /* End PBXGroup section */ 124 | 125 | /* Begin PBXNativeTarget section */ 126 | 339538F01ADF2C270047B47B /* ApnsDemo */ = { 127 | isa = PBXNativeTarget; 128 | buildConfigurationList = 339539101ADF2C280047B47B /* Build configuration list for PBXNativeTarget "ApnsDemo" */; 129 | buildPhases = ( 130 | 339538ED1ADF2C270047B47B /* Sources */, 131 | 339538EE1ADF2C270047B47B /* Frameworks */, 132 | 339538EF1ADF2C270047B47B /* Resources */, 133 | ); 134 | buildRules = ( 135 | ); 136 | dependencies = ( 137 | ); 138 | name = ApnsDemo; 139 | productName = ApnsDemo; 140 | productReference = 339538F11ADF2C270047B47B /* ApnsDemo.app */; 141 | productType = "com.apple.product-type.application"; 142 | }; 143 | 339539051ADF2C280047B47B /* ApnsDemoTests */ = { 144 | isa = PBXNativeTarget; 145 | buildConfigurationList = 339539131ADF2C280047B47B /* Build configuration list for PBXNativeTarget "ApnsDemoTests" */; 146 | buildPhases = ( 147 | 339539021ADF2C280047B47B /* Sources */, 148 | 339539031ADF2C280047B47B /* Frameworks */, 149 | 339539041ADF2C280047B47B /* Resources */, 150 | ); 151 | buildRules = ( 152 | ); 153 | dependencies = ( 154 | 339539081ADF2C280047B47B /* PBXTargetDependency */, 155 | ); 156 | name = ApnsDemoTests; 157 | productName = ApnsDemoTests; 158 | productReference = 339539061ADF2C280047B47B /* ApnsDemoTests.xctest */; 159 | productType = "com.apple.product-type.bundle.unit-test"; 160 | }; 161 | /* End PBXNativeTarget section */ 162 | 163 | /* Begin PBXProject section */ 164 | 339538E91ADF2C270047B47B /* Project object */ = { 165 | isa = PBXProject; 166 | attributes = { 167 | LastUpgradeCheck = 0630; 168 | ORGANIZATIONNAME = "Ryan Paul"; 169 | TargetAttributes = { 170 | 339538F01ADF2C270047B47B = { 171 | CreatedOnToolsVersion = 6.3; 172 | }; 173 | 339539051ADF2C280047B47B = { 174 | CreatedOnToolsVersion = 6.3; 175 | TestTargetID = 339538F01ADF2C270047B47B; 176 | }; 177 | }; 178 | }; 179 | buildConfigurationList = 339538EC1ADF2C270047B47B /* Build configuration list for PBXProject "ApnsDemo" */; 180 | compatibilityVersion = "Xcode 3.2"; 181 | developmentRegion = English; 182 | hasScannedForEncodings = 0; 183 | knownRegions = ( 184 | en, 185 | Base, 186 | ); 187 | mainGroup = 339538E81ADF2C270047B47B; 188 | productRefGroup = 339538F21ADF2C270047B47B /* Products */; 189 | projectDirPath = ""; 190 | projectRoot = ""; 191 | targets = ( 192 | 339538F01ADF2C270047B47B /* ApnsDemo */, 193 | 339539051ADF2C280047B47B /* ApnsDemoTests */, 194 | ); 195 | }; 196 | /* End PBXProject section */ 197 | 198 | /* Begin PBXResourcesBuildPhase section */ 199 | 339538EF1ADF2C270047B47B /* Resources */ = { 200 | isa = PBXResourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | 339538FC1ADF2C270047B47B /* Main.storyboard in Resources */, 204 | 339539011ADF2C270047B47B /* LaunchScreen.xib in Resources */, 205 | 339538FE1ADF2C270047B47B /* Images.xcassets in Resources */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | 339539041ADF2C280047B47B /* Resources */ = { 210 | isa = PBXResourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | }; 216 | /* End PBXResourcesBuildPhase section */ 217 | 218 | /* Begin PBXSourcesBuildPhase section */ 219 | 339538ED1ADF2C270047B47B /* Sources */ = { 220 | isa = PBXSourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | 339538F91ADF2C270047B47B /* ViewController.swift in Sources */, 224 | 339538F71ADF2C270047B47B /* AppDelegate.swift in Sources */, 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | 339539021ADF2C280047B47B /* Sources */ = { 229 | isa = PBXSourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 3395390D1ADF2C280047B47B /* ApnsDemoTests.swift in Sources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | /* End PBXSourcesBuildPhase section */ 237 | 238 | /* Begin PBXTargetDependency section */ 239 | 339539081ADF2C280047B47B /* PBXTargetDependency */ = { 240 | isa = PBXTargetDependency; 241 | target = 339538F01ADF2C270047B47B /* ApnsDemo */; 242 | targetProxy = 339539071ADF2C280047B47B /* PBXContainerItemProxy */; 243 | }; 244 | /* End PBXTargetDependency section */ 245 | 246 | /* Begin PBXVariantGroup section */ 247 | 339538FA1ADF2C270047B47B /* Main.storyboard */ = { 248 | isa = PBXVariantGroup; 249 | children = ( 250 | 339538FB1ADF2C270047B47B /* Base */, 251 | ); 252 | name = Main.storyboard; 253 | sourceTree = ""; 254 | }; 255 | 339538FF1ADF2C270047B47B /* LaunchScreen.xib */ = { 256 | isa = PBXVariantGroup; 257 | children = ( 258 | 339539001ADF2C270047B47B /* Base */, 259 | ); 260 | name = LaunchScreen.xib; 261 | sourceTree = ""; 262 | }; 263 | /* End PBXVariantGroup section */ 264 | 265 | /* Begin XCBuildConfiguration section */ 266 | 3395390E1ADF2C280047B47B /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ALWAYS_SEARCH_USER_PATHS = NO; 270 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 271 | CLANG_CXX_LIBRARY = "libc++"; 272 | CLANG_ENABLE_MODULES = YES; 273 | CLANG_ENABLE_OBJC_ARC = YES; 274 | CLANG_WARN_BOOL_CONVERSION = YES; 275 | CLANG_WARN_CONSTANT_CONVERSION = YES; 276 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 277 | CLANG_WARN_EMPTY_BODY = YES; 278 | CLANG_WARN_ENUM_CONVERSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_UNREACHABLE_CODE = YES; 282 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 283 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 284 | COPY_PHASE_STRIP = NO; 285 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 286 | ENABLE_STRICT_OBJC_MSGSEND = YES; 287 | GCC_C_LANGUAGE_STANDARD = gnu99; 288 | GCC_DYNAMIC_NO_PIC = NO; 289 | GCC_NO_COMMON_BLOCKS = YES; 290 | GCC_OPTIMIZATION_LEVEL = 0; 291 | GCC_PREPROCESSOR_DEFINITIONS = ( 292 | "DEBUG=1", 293 | "$(inherited)", 294 | ); 295 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 298 | GCC_WARN_UNDECLARED_SELECTOR = YES; 299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 300 | GCC_WARN_UNUSED_FUNCTION = YES; 301 | GCC_WARN_UNUSED_VARIABLE = YES; 302 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 303 | MTL_ENABLE_DEBUG_INFO = YES; 304 | ONLY_ACTIVE_ARCH = YES; 305 | SDKROOT = iphoneos; 306 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 307 | }; 308 | name = Debug; 309 | }; 310 | 3395390F1ADF2C280047B47B /* Release */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ALWAYS_SEARCH_USER_PATHS = NO; 314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 315 | CLANG_CXX_LIBRARY = "libc++"; 316 | CLANG_ENABLE_MODULES = YES; 317 | CLANG_ENABLE_OBJC_ARC = YES; 318 | CLANG_WARN_BOOL_CONVERSION = YES; 319 | CLANG_WARN_CONSTANT_CONVERSION = YES; 320 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 321 | CLANG_WARN_EMPTY_BODY = YES; 322 | CLANG_WARN_ENUM_CONVERSION = YES; 323 | CLANG_WARN_INT_CONVERSION = YES; 324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 325 | CLANG_WARN_UNREACHABLE_CODE = YES; 326 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 327 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 328 | COPY_PHASE_STRIP = NO; 329 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 330 | ENABLE_NS_ASSERTIONS = NO; 331 | ENABLE_STRICT_OBJC_MSGSEND = YES; 332 | GCC_C_LANGUAGE_STANDARD = gnu99; 333 | GCC_NO_COMMON_BLOCKS = YES; 334 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 335 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 336 | GCC_WARN_UNDECLARED_SELECTOR = YES; 337 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 338 | GCC_WARN_UNUSED_FUNCTION = YES; 339 | GCC_WARN_UNUSED_VARIABLE = YES; 340 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 341 | MTL_ENABLE_DEBUG_INFO = NO; 342 | SDKROOT = iphoneos; 343 | VALIDATE_PRODUCT = YES; 344 | }; 345 | name = Release; 346 | }; 347 | 339539111ADF2C280047B47B /* Debug */ = { 348 | isa = XCBuildConfiguration; 349 | buildSettings = { 350 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 351 | INFOPLIST_FILE = ApnsDemo/Info.plist; 352 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | }; 355 | name = Debug; 356 | }; 357 | 339539121ADF2C280047B47B /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 361 | INFOPLIST_FILE = ApnsDemo/Info.plist; 362 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | }; 365 | name = Release; 366 | }; 367 | 339539141ADF2C280047B47B /* Debug */ = { 368 | isa = XCBuildConfiguration; 369 | buildSettings = { 370 | BUNDLE_LOADER = "$(TEST_HOST)"; 371 | FRAMEWORK_SEARCH_PATHS = ( 372 | "$(SDKROOT)/Developer/Library/Frameworks", 373 | "$(inherited)", 374 | ); 375 | GCC_PREPROCESSOR_DEFINITIONS = ( 376 | "DEBUG=1", 377 | "$(inherited)", 378 | ); 379 | INFOPLIST_FILE = ApnsDemoTests/Info.plist; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 381 | PRODUCT_NAME = "$(TARGET_NAME)"; 382 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ApnsDemo.app/ApnsDemo"; 383 | }; 384 | name = Debug; 385 | }; 386 | 339539151ADF2C280047B47B /* Release */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | BUNDLE_LOADER = "$(TEST_HOST)"; 390 | FRAMEWORK_SEARCH_PATHS = ( 391 | "$(SDKROOT)/Developer/Library/Frameworks", 392 | "$(inherited)", 393 | ); 394 | INFOPLIST_FILE = ApnsDemoTests/Info.plist; 395 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 396 | PRODUCT_NAME = "$(TARGET_NAME)"; 397 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ApnsDemo.app/ApnsDemo"; 398 | }; 399 | name = Release; 400 | }; 401 | /* End XCBuildConfiguration section */ 402 | 403 | /* Begin XCConfigurationList section */ 404 | 339538EC1ADF2C270047B47B /* Build configuration list for PBXProject "ApnsDemo" */ = { 405 | isa = XCConfigurationList; 406 | buildConfigurations = ( 407 | 3395390E1ADF2C280047B47B /* Debug */, 408 | 3395390F1ADF2C280047B47B /* Release */, 409 | ); 410 | defaultConfigurationIsVisible = 0; 411 | defaultConfigurationName = Release; 412 | }; 413 | 339539101ADF2C280047B47B /* Build configuration list for PBXNativeTarget "ApnsDemo" */ = { 414 | isa = XCConfigurationList; 415 | buildConfigurations = ( 416 | 339539111ADF2C280047B47B /* Debug */, 417 | 339539121ADF2C280047B47B /* Release */, 418 | ); 419 | defaultConfigurationIsVisible = 0; 420 | }; 421 | 339539131ADF2C280047B47B /* Build configuration list for PBXNativeTarget "ApnsDemoTests" */ = { 422 | isa = XCConfigurationList; 423 | buildConfigurations = ( 424 | 339539141ADF2C280047B47B /* Debug */, 425 | 339539151ADF2C280047B47B /* Release */, 426 | ); 427 | defaultConfigurationIsVisible = 0; 428 | }; 429 | /* End XCConfigurationList section */ 430 | }; 431 | rootObject = 339538E91ADF2C270047B47B /* Project object */; 432 | } 433 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/project.xcworkspace/xcuserdata/segphault.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rethinkdb/rethinkdb-mobile-push/003dbeef7e10a071280b7077f3db7d9b470dd95c/ios-client/ApnsDemo.xcodeproj/project.xcworkspace/xcuserdata/segphault.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/xcuserdata/segphault.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/xcuserdata/segphault.xcuserdatad/xcschemes/ApnsDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo.xcodeproj/xcuserdata/segphault.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ApnsDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 339538F01ADF2C270047B47B 16 | 17 | primary 18 | 19 | 20 | 339539051ADF2C280047B47B 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ApnsDemo 4 | // 5 | // Created by Ryan Paul on 4/15/15. 6 | // Copyright (c) 2015 Ryan Paul. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | var deviceToken: String? 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | var settings = UIUserNotificationSettings(forTypes: .Badge | .Alert | .Sound, categories: nil) 19 | application.registerUserNotificationSettings(settings) 20 | application.registerForRemoteNotifications() 21 | return true 22 | } 23 | 24 | func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 25 | self.deviceToken = deviceToken.description 26 | } 27 | 28 | func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 29 | println(error.localizedDescription) 30 | } 31 | 32 | func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 33 | if let coords = userInfo["coordinates"] as? NSArray, lon = coords[0] as? Double, lat = coords[1] as? Double { 34 | var view = window?.rootViewController as? ViewController 35 | view?.addMapAnnotation(lon, lat: lat) 36 | } 37 | } 38 | 39 | func applicationWillResignActive(application: UIApplication) { 40 | // 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. 41 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 42 | } 43 | 44 | func applicationDidEnterBackground(application: UIApplication) { 45 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 46 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 47 | } 48 | 49 | func applicationWillEnterForeground(application: UIApplication) { 50 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 51 | } 52 | 53 | func applicationDidBecomeActive(application: UIApplication) { 54 | // 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. 55 | } 56 | 57 | func applicationWillTerminate(application: UIApplication) { 58 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 59 | } 60 | 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ios-client/ApnsDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | net.phault.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | NSLocationWhenInUseUsageDescription 30 | 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ios-client/ApnsDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ApnsDemo 4 | // 5 | // Created by Ryan Paul on 4/15/15. 6 | // Copyright (c) 2015 Ryan Paul. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import MapKit 11 | import CoreLocation 12 | 13 | class ViewController: UIViewController, UINavigationBarDelegate, CLLocationManagerDelegate { 14 | 15 | var locationManager: CLLocationManager! 16 | var checkedForPoints: Bool! 17 | 18 | @IBOutlet weak var navBar: UINavigationBar! 19 | @IBOutlet weak var mapView: MKMapView! 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | 24 | navBar.delegate = self 25 | checkedForPoints = false 26 | 27 | locationManager = CLLocationManager() 28 | locationManager.delegate = self 29 | locationManager.desiredAccuracy = kCLLocationAccuracyBest 30 | locationManager.requestWhenInUseAuthorization() 31 | locationManager.startUpdatingLocation() 32 | 33 | mapView.showsUserLocation = true; 34 | } 35 | 36 | override func didReceiveMemoryWarning() { 37 | super.didReceiveMemoryWarning() 38 | } 39 | 40 | func positionForBar(bar: UIBarPositioning) -> UIBarPosition { 41 | return UIBarPosition.TopAttached 42 | } 43 | 44 | func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 45 | if (checkedForPoints == true) { return } 46 | checkedForPoints = true 47 | 48 | var position = locationManager.location.coordinate 49 | var url = "http://youraddress.ngrok.com/api/pins?place=\(position.latitude),\(position.longitude)" 50 | var req = NSURLRequest(URL: NSURL(string: url)!) 51 | 52 | NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue.mainQueue()) {(resp, data, err) in 53 | if let places = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? NSArray { 54 | for place in places as! [NSDictionary] { 55 | if let coords = place["coordinates"] as? NSArray, lon = coords[0] as? Double, lat = coords[1] as? Double { 56 | self.addMapAnnotation(lon, lat: lat) 57 | } 58 | } 59 | } 60 | } 61 | } 62 | 63 | func addMapAnnotation(lon: Double, lat: Double) { 64 | var newPin = MKPointAnnotation() 65 | newPin.coordinate = CLLocationCoordinate2DMake(lat, lon) 66 | mapView.addAnnotation(newPin) 67 | } 68 | 69 | @IBAction func sendMessage(sender: AnyObject) { 70 | var position = locationManager.location.coordinate 71 | var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 72 | 73 | var params = Dictionary() 74 | params["place"] = [position.latitude, position.longitude] 75 | params["token"] = appDelegate.deviceToken 76 | 77 | var req = NSMutableURLRequest(URL: NSURL(string: "http://youraddress.ngrok.com/api/checkin")!) 78 | req.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: nil) 79 | req.HTTPMethod = "POST" 80 | 81 | req.addValue("application/json", forHTTPHeaderField: "Content-Type") 82 | req.addValue("application/json", forHTTPHeaderField: "Accept") 83 | 84 | NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue.mainQueue()) {(resp, data, err) in 85 | if let output = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? NSDictionary { 86 | println(output["success"] as? Bool) 87 | } 88 | } 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /ios-client/ApnsDemoTests/ApnsDemoTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ApnsDemoTests.swift 3 | // ApnsDemoTests 4 | // 5 | // Created by Ryan Paul on 4/15/15. 6 | // Copyright (c) 2015 Ryan Paul. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class ApnsDemoTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ios-client/ApnsDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | net.phault.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "express": "~4.12.3", 4 | "rethinkdb": "~1.16.2", 5 | "socket.io": "~1.3.5", 6 | "body-parser": "~1.12.2", 7 | "apn": "~1.7.3" 8 | } 9 | } 10 | --------------------------------------------------------------------------------