├── .gitignore ├── CoreMotionPost.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── kamilwysocki.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── xcschemes │ │ └── xcschememanagement.plist └── xcuserdata │ └── kamilwysocki.xcuserdatad │ └── xcschemes │ ├── CoreMotionPost.xcscheme │ └── xcschememanagement.plist ├── CoreMotionPost ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .DS_Store -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B445E13FD5F57FD98F58059C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B445EFFC83F4C00FFE297DEE /* LaunchScreen.storyboard */; }; 11 | B445E39595BC87A8BD1ED04B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B445EAD16DF479DBABDEEFDA /* ViewController.swift */; }; 12 | B445EA24F5AC2FA4B408284E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B445EA0D01366C92C93AB459 /* Main.storyboard */; }; 13 | B445EE9574104E706CACACEB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B445E421F21192B45C6C070A /* Assets.xcassets */; }; 14 | B445EFABAA41AD4D36CB8153 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B445E0F478CF14D23745A127 /* AppDelegate.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | B445E0F478CF14D23745A127 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 19 | B445E1D5FC8970F5174D2FC1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 20 | B445E1F619176D0759D1A16A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.info; path = Info.plist; sourceTree = ""; }; 21 | B445E1F85A708A226CB2BACC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | B445E421F21192B45C6C070A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | B445E46293149715037201A3 /* CoreMotionPost.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoreMotionPost.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | B445EAD16DF479DBABDEEFDA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | B445EFCC1240094B8C97EE34 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | B445E29D78FFA66496D0D366 /* Products */ = { 39 | isa = PBXGroup; 40 | children = ( 41 | B445E46293149715037201A3 /* CoreMotionPost.app */, 42 | ); 43 | name = Products; 44 | sourceTree = ""; 45 | }; 46 | B445E53632959D52D7C5E164 = { 47 | isa = PBXGroup; 48 | children = ( 49 | B445E29D78FFA66496D0D366 /* Products */, 50 | B445EB5ED58CFDC35D8C3D27 /* CoreMotionPost */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | B445EB5ED58CFDC35D8C3D27 /* CoreMotionPost */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | B445E1F619176D0759D1A16A /* Info.plist */, 58 | B445E421F21192B45C6C070A /* Assets.xcassets */, 59 | B445EFFC83F4C00FFE297DEE /* LaunchScreen.storyboard */, 60 | B445E0F478CF14D23745A127 /* AppDelegate.swift */, 61 | B445EA0D01366C92C93AB459 /* Main.storyboard */, 62 | B445EAD16DF479DBABDEEFDA /* ViewController.swift */, 63 | ); 64 | path = CoreMotionPost; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | B445EEF2C4C450C6F8AB82D4 /* CoreMotionPost */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = B445EEE5CD756E3300C14BC0 /* Build configuration list for PBXNativeTarget "CoreMotionPost" */; 73 | buildPhases = ( 74 | B445E4C451A7171333293DCA /* Sources */, 75 | B445EFCC1240094B8C97EE34 /* Frameworks */, 76 | B445E3E958931DCCAD3F2F28 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = CoreMotionPost; 83 | productName = CoreMotionPost; 84 | productReference = B445E46293149715037201A3 /* CoreMotionPost.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | B445E4FEF6171DFCCCC4EF10 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | ORGANIZATIONNAME = kamwysoc; 94 | TargetAttributes = { 95 | B445EEF2C4C450C6F8AB82D4 = { 96 | DevelopmentTeam = CBE57AW4A4; 97 | }; 98 | }; 99 | }; 100 | buildConfigurationList = B445E7F3A507E636BE3EA0A6 /* Build configuration list for PBXProject "CoreMotionPost" */; 101 | compatibilityVersion = "Xcode 3.2"; 102 | developmentRegion = English; 103 | hasScannedForEncodings = 0; 104 | knownRegions = ( 105 | en, 106 | ); 107 | mainGroup = B445E53632959D52D7C5E164; 108 | productRefGroup = B445E29D78FFA66496D0D366 /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | B445EEF2C4C450C6F8AB82D4 /* CoreMotionPost */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXResourcesBuildPhase section */ 118 | B445E3E958931DCCAD3F2F28 /* Resources */ = { 119 | isa = PBXResourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | B445EE9574104E706CACACEB /* Assets.xcassets in Resources */, 123 | B445E13FD5F57FD98F58059C /* LaunchScreen.storyboard in Resources */, 124 | B445EA24F5AC2FA4B408284E /* Main.storyboard in Resources */, 125 | ); 126 | runOnlyForDeploymentPostprocessing = 0; 127 | }; 128 | /* End PBXResourcesBuildPhase section */ 129 | 130 | /* Begin PBXSourcesBuildPhase section */ 131 | B445E4C451A7171333293DCA /* Sources */ = { 132 | isa = PBXSourcesBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | B445EFABAA41AD4D36CB8153 /* AppDelegate.swift in Sources */, 136 | B445E39595BC87A8BD1ED04B /* ViewController.swift in Sources */, 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXSourcesBuildPhase section */ 141 | 142 | /* Begin PBXVariantGroup section */ 143 | B445EA0D01366C92C93AB459 /* Main.storyboard */ = { 144 | isa = PBXVariantGroup; 145 | children = ( 146 | B445E1F85A708A226CB2BACC /* Base */, 147 | ); 148 | name = Main.storyboard; 149 | sourceTree = ""; 150 | }; 151 | B445EFFC83F4C00FFE297DEE /* LaunchScreen.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | B445E1D5FC8970F5174D2FC1 /* Base */, 155 | ); 156 | name = LaunchScreen.storyboard; 157 | sourceTree = ""; 158 | }; 159 | /* End PBXVariantGroup section */ 160 | 161 | /* Begin XCBuildConfiguration section */ 162 | B445E558353B51C1815FBE8D /* Debug */ = { 163 | isa = XCBuildConfiguration; 164 | buildSettings = { 165 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 166 | DEVELOPMENT_TEAM = CBE57AW4A4; 167 | INFOPLIST_FILE = CoreMotionPost/Info.plist; 168 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 169 | PRODUCT_BUNDLE_IDENTIFIER = kamwysoc.CoreMotionPost; 170 | PRODUCT_NAME = "$(TARGET_NAME)"; 171 | SWIFT_VERSION = 4.0; 172 | TARGETED_DEVICE_FAMILY = "1,2"; 173 | }; 174 | name = Debug; 175 | }; 176 | B445E6FD0C2CE7042B0B0F26 /* Debug */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_ANALYZER_NONNULL = YES; 181 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 183 | CLANG_CXX_LIBRARY = "libc++"; 184 | CLANG_ENABLE_MODULES = YES; 185 | CLANG_ENABLE_OBJC_ARC = YES; 186 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 187 | CLANG_WARN_BOOL_CONVERSION = YES; 188 | CLANG_WARN_COMMA = YES; 189 | CLANG_WARN_CONSTANT_CONVERSION = YES; 190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 191 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 192 | CLANG_WARN_EMPTY_BODY = YES; 193 | CLANG_WARN_ENUM_CONVERSION = YES; 194 | CLANG_WARN_INFINITE_RECURSION = YES; 195 | CLANG_WARN_INT_CONVERSION = YES; 196 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | CODE_SIGN_IDENTITY = "iPhone Developer"; 206 | COPY_PHASE_STRIP = NO; 207 | DEBUG_INFORMATION_FORMAT = dwarf; 208 | ENABLE_STRICT_OBJC_MSGSEND = YES; 209 | ENABLE_TESTABILITY = YES; 210 | GCC_C_LANGUAGE_STANDARD = gnu11; 211 | GCC_DYNAMIC_NO_PIC = NO; 212 | GCC_NO_COMMON_BLOCKS = YES; 213 | GCC_OPTIMIZATION_LEVEL = 0; 214 | GCC_PREPROCESSOR_DEFINITIONS = ( 215 | "DEBUG=1", 216 | "$(inherited)", 217 | ); 218 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 219 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 220 | GCC_WARN_UNDECLARED_SELECTOR = YES; 221 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 222 | GCC_WARN_UNUSED_FUNCTION = YES; 223 | GCC_WARN_UNUSED_VARIABLE = YES; 224 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 225 | MTL_ENABLE_DEBUG_INFO = YES; 226 | ONLY_ACTIVE_ARCH = YES; 227 | SDKROOT = iphoneos; 228 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 229 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 230 | }; 231 | name = Debug; 232 | }; 233 | B445EA23D0B232937EEA6DCA /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_COMMA = YES; 246 | CLANG_WARN_CONSTANT_CONVERSION = YES; 247 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 248 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INFINITE_RECURSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 255 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 256 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 257 | CLANG_WARN_STRICT_PROTOTYPES = YES; 258 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 259 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | CODE_SIGN_IDENTITY = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 265 | ENABLE_NS_ASSERTIONS = NO; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | GCC_C_LANGUAGE_STANDARD = gnu11; 268 | GCC_NO_COMMON_BLOCKS = YES; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 276 | MTL_ENABLE_DEBUG_INFO = NO; 277 | SDKROOT = iphoneos; 278 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 279 | VALIDATE_PRODUCT = YES; 280 | }; 281 | name = Release; 282 | }; 283 | B445EA6DB7C9BA62B31F2E86 /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | DEVELOPMENT_TEAM = CBE57AW4A4; 288 | INFOPLIST_FILE = CoreMotionPost/Info.plist; 289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 290 | PRODUCT_BUNDLE_IDENTIFIER = kamwysoc.CoreMotionPost; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | SWIFT_VERSION = 4.0; 293 | TARGETED_DEVICE_FAMILY = "1,2"; 294 | }; 295 | name = Release; 296 | }; 297 | /* End XCBuildConfiguration section */ 298 | 299 | /* Begin XCConfigurationList section */ 300 | B445E7F3A507E636BE3EA0A6 /* Build configuration list for PBXProject "CoreMotionPost" */ = { 301 | isa = XCConfigurationList; 302 | buildConfigurations = ( 303 | B445E6FD0C2CE7042B0B0F26 /* Debug */, 304 | B445EA23D0B232937EEA6DCA /* Release */, 305 | ); 306 | defaultConfigurationIsVisible = 0; 307 | defaultConfigurationName = Release; 308 | }; 309 | B445EEE5CD756E3300C14BC0 /* Build configuration list for PBXNativeTarget "CoreMotionPost" */ = { 310 | isa = XCConfigurationList; 311 | buildConfigurations = ( 312 | B445E558353B51C1815FBE8D /* Debug */, 313 | B445EA6DB7C9BA62B31F2E86 /* Release */, 314 | ); 315 | defaultConfigurationIsVisible = 0; 316 | defaultConfigurationName = Release; 317 | }; 318 | /* End XCConfigurationList section */ 319 | }; 320 | rootObject = B445E4FEF6171DFCCCC4EF10 /* Project object */; 321 | } 322 | -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/project.xcworkspace/xcuserdata/kamilwysocki.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bright/Pedometer-Swift/15ae6f8e64133b7c6dda37b85897593206fa0612/CoreMotionPost.xcodeproj/project.xcworkspace/xcuserdata/kamilwysocki.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/project.xcworkspace/xcuserdata/kamilwysocki.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/xcuserdata/kamilwysocki.xcuserdatad/xcschemes/CoreMotionPost.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /CoreMotionPost.xcodeproj/xcuserdata/kamilwysocki.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CoreMotionPost.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /CoreMotionPost/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CoreMotionPost 4 | // 5 | // Created by Kamil Wysocki on 07/12/2017. 6 | // Copyright © 2017 kamwysoc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | 19 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 20 | // Override point for customization after application launch. 21 | return true 22 | } 23 | 24 | 25 | func applicationWillResignActive(_ application: UIApplication) { 26 | // 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. 27 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 28 | 29 | } 30 | 31 | 32 | func applicationDidEnterBackground(_ application: UIApplication) { 33 | // 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. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | 36 | } 37 | 38 | 39 | func applicationWillEnterForeground(_ application: UIApplication) { 40 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 41 | } 42 | 43 | 44 | func applicationDidBecomeActive(_ application: UIApplication) { 45 | // 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. 46 | } 47 | 48 | 49 | func applicationWillTerminate(_ application: UIApplication) { 50 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 51 | } 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /CoreMotionPost/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /CoreMotionPost/Base.lproj/LaunchScreen.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 | -------------------------------------------------------------------------------- /CoreMotionPost/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 | 30 | 39 | 45 | 54 | 60 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /CoreMotionPost/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSMotionUsageDescription 24 | In order to count steps I need an access to your pedometer 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CoreMotionPost/ViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import CoreMotion 3 | import Dispatch 4 | 5 | 6 | class ViewController: UIViewController { 7 | 8 | private let activityManager = CMMotionActivityManager() 9 | private let pedometer = CMPedometer() 10 | private var shouldStartUpdating: Bool = false 11 | private var startDate: Date? = nil 12 | 13 | @IBOutlet weak var startButton: UIButton! 14 | @IBOutlet weak var stepsCountLabel: UILabel! 15 | @IBOutlet weak var activityTypeLabel: UILabel! 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | startButton.addTarget(self, action: #selector(didTapStartButton), for: .touchUpInside) 20 | } 21 | 22 | override func viewWillAppear(_ animated: Bool) { 23 | super.viewWillAppear(animated) 24 | guard let startDate = startDate else { return } 25 | updateStepsCountLabelUsing(startDate: startDate) 26 | } 27 | 28 | @objc private func didTapStartButton() { 29 | shouldStartUpdating = !shouldStartUpdating 30 | shouldStartUpdating ? (onStart()) : (onStop()) 31 | } 32 | } 33 | 34 | 35 | extension ViewController { 36 | private func onStart() { 37 | startButton.setTitle("Stop", for: .normal) 38 | startDate = Date() 39 | checkAuthorizationStatus() 40 | startUpdating() 41 | } 42 | 43 | private func onStop() { 44 | startButton.setTitle("Start", for: .normal) 45 | startDate = nil 46 | stopUpdating() 47 | } 48 | 49 | private func startUpdating() { 50 | if CMMotionActivityManager.isActivityAvailable() { 51 | startTrackingActivityType() 52 | } else { 53 | activityTypeLabel.text = "Not available" 54 | } 55 | 56 | if CMPedometer.isStepCountingAvailable() { 57 | startCountingSteps() 58 | } else { 59 | stepsCountLabel.text = "Not available" 60 | } 61 | } 62 | 63 | private func checkAuthorizationStatus() { 64 | switch CMMotionActivityManager.authorizationStatus() { 65 | case CMAuthorizationStatus.denied: 66 | onStop() 67 | activityTypeLabel.text = "Not available" 68 | stepsCountLabel.text = "Not available" 69 | default:break 70 | } 71 | } 72 | 73 | private func stopUpdating() { 74 | activityManager.stopActivityUpdates() 75 | pedometer.stopUpdates() 76 | pedometer.stopEventUpdates() 77 | } 78 | 79 | private func on(error: Error) { 80 | //handle error 81 | } 82 | 83 | private func updateStepsCountLabelUsing(startDate: Date) { 84 | pedometer.queryPedometerData(from: startDate, to: Date()) { 85 | [weak self] pedometerData, error in 86 | if let error = error { 87 | self?.on(error: error) 88 | } else if let pedometerData = pedometerData { 89 | DispatchQueue.main.async { 90 | self?.stepsCountLabel.text = String(describing: pedometerData.numberOfSteps) 91 | } 92 | } 93 | } 94 | } 95 | 96 | private func startTrackingActivityType() { 97 | activityManager.startActivityUpdates(to: OperationQueue.main) { 98 | [weak self] (activity: CMMotionActivity?) in 99 | guard let activity = activity else { return } 100 | DispatchQueue.main.async { 101 | if activity.walking { 102 | self?.activityTypeLabel.text = "Walking" 103 | } else if activity.stationary { 104 | self?.activityTypeLabel.text = "Stationary" 105 | } else if activity.running { 106 | self?.activityTypeLabel.text = "Running" 107 | } else if activity.automotive { 108 | self?.activityTypeLabel.text = "Automotive" 109 | } 110 | } 111 | } 112 | } 113 | 114 | private func startCountingSteps() { 115 | pedometer.startUpdates(from: Date()) { 116 | [weak self] pedometerData, error in 117 | guard let pedometerData = pedometerData, error == nil else { return } 118 | 119 | DispatchQueue.main.async { 120 | self?.stepsCountLabel.text = pedometerData.numberOfSteps.stringValue 121 | } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | More about project you can find at https://brightinventions.pl/blog/coremotion-pedometer-swift/ 2 | --------------------------------------------------------------------------------