├── .gitignore ├── LICENSE ├── README.md ├── SJAnalyticsDemo ├── SJAnalyticsDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── SJAnalyticsDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── SJAnalyticsDemoTests │ ├── Info.plist │ └── SJAnalyticsDemoTests.m └── SJAnalyticsDemoUITests │ ├── Info.plist │ └── SJAnalyticsDemoUITests.m └── codes ├── SJAnalytics.h ├── SJAnalytics.m ├── SJAnalyticsConstants.h ├── SJAnalyticsConstants.m ├── SJAnalyticsProvider.h ├── UIApplication+SJAnalytics.h └── UIApplication+SJAnalytics.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jseanj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SJAnalytics 2 | 一个无侵入的统计打点框架 3 | 4 | ## 功能 5 | 6 | - 可以配置统计打点时所需要的全部信息,包括实例和调用方法的参数 7 | - 可以配置是否触发统计打点 8 | - 支持在block中回调统计打点 9 | - 支持屏幕事件统计打点 10 | 11 | ## 原理 12 | 13 | 该框架主要监听两类事件:方法调用和点击事件。其中方法调用的事件监听是通过将原始方法的调用指向消息转发的流程,然后通过重写 `forwardInvocation` 获取原始方法的参数等信息进行打点;点击事件的监听是通过重写 `UIApplication` 的 `sendAction:to:from:forEvent:` 获取到 `target` 和 `selector` 进行打点。点击事件的监听也可以通过前者来实现,但是为了避免消息转发带来的性能损耗,建议点击事件的监听用后者来实现。 14 | 15 | ## Example 16 | 17 | ```objc 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | [[SJAnalytics shared] configure: 21 | @{ 22 | SJAnalyticsMethodCall: @[ 23 | @{ 24 | SJAnalyticsClass:ViewController.class, 25 | SJAnalyticsDetails: @[ 26 | @{ 27 | SJAnalyticsEvent: @"testNoParamsEvent", 28 | SJAnalyticsSelector: NSStringFromSelector(@selector(testNoParams)), 29 | SJAnalyticsShouldExecute:^BOOL(ViewController *instance, NSArray *params) { 30 | return NO; 31 | }, 32 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 33 | return @{}; 34 | } 35 | }, 36 | @{ 37 | SJAnalyticsEvent: @"testParamsEvent", 38 | SJAnalyticsSelector: NSStringFromSelector(@selector(testParams:)), 39 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 40 | return @{}; 41 | } 42 | }, 43 | @{ 44 | SJAnalyticsEvent: @"testBlockSuccessEvent", 45 | SJAnalyticsSelector: NSStringFromSelector(@selector(testBlockSuccess:failure:)), 46 | SJAnalyticsShouldExecute:^BOOL(ViewController *instance, NSArray *params) { 47 | if ([params[0] isKindOfClass:[NSNull class]]) { 48 | return NO; 49 | } else { 50 | return YES; 51 | } 52 | }, 53 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 54 | return @{}; 55 | } 56 | } 57 | ] 58 | } 59 | ], 60 | SJAnalyticsUIControl: @[ 61 | @{ 62 | SJAnalyticsClass:ViewController.class, 63 | SJAnalyticsDetails: @[ 64 | @{ 65 | SJAnalyticsEvent: @"btnTappedEvent", 66 | SJAnalyticsSelector: @"btnTapped:", 67 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 68 | return @{}; 69 | } 70 | } 71 | ] 72 | } 73 | ] 74 | } provider:self]; 75 | } 76 | ``` 77 | 78 | ```objc 79 | - (void)event:(NSString *)event withParameters:(NSDictionary *)parameters { 80 | // log your event 81 | } 82 | ``` -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A81DA6E51E89057D00B81195 /* UIApplication+SJAnalytics.m in Sources */ = {isa = PBXBuildFile; fileRef = A81DA6E01E88EAE500B81195 /* UIApplication+SJAnalytics.m */; }; 11 | A81DA6E61E89058000B81195 /* SJAnalyticsConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = A81DA6E41E89030700B81195 /* SJAnalyticsConstants.m */; }; 12 | A81DA6E71E89058400B81195 /* SJAnalytics.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399CAC1E8518A400396620 /* SJAnalytics.m */; }; 13 | A8399C791E85182900396620 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399C781E85182900396620 /* main.m */; }; 14 | A8399C7C1E85182900396620 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399C7B1E85182900396620 /* AppDelegate.m */; }; 15 | A8399C7F1E85182900396620 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399C7E1E85182900396620 /* ViewController.m */; }; 16 | A8399C821E85182900396620 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A8399C801E85182900396620 /* Main.storyboard */; }; 17 | A8399C841E85182900396620 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A8399C831E85182900396620 /* Assets.xcassets */; }; 18 | A8399C871E85182900396620 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A8399C851E85182900396620 /* LaunchScreen.storyboard */; }; 19 | A8399C921E85182900396620 /* SJAnalyticsDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399C911E85182900396620 /* SJAnalyticsDemoTests.m */; }; 20 | A8399C9D1E85182900396620 /* SJAnalyticsDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = A8399C9C1E85182900396620 /* SJAnalyticsDemoUITests.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | A8399C8E1E85182900396620 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = A8399C6C1E85182800396620 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = A8399C731E85182800396620; 29 | remoteInfo = SJAnalyticsDemo; 30 | }; 31 | A8399C991E85182900396620 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = A8399C6C1E85182800396620 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = A8399C731E85182800396620; 36 | remoteInfo = SJAnalyticsDemo; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | A81DA6DF1E88EAE500B81195 /* UIApplication+SJAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIApplication+SJAnalytics.h"; sourceTree = ""; }; 42 | A81DA6E01E88EAE500B81195 /* UIApplication+SJAnalytics.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+SJAnalytics.m"; sourceTree = ""; }; 43 | A81DA6E21E88F99B00B81195 /* SJAnalyticsProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SJAnalyticsProvider.h; sourceTree = ""; }; 44 | A81DA6E31E89030700B81195 /* SJAnalyticsConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SJAnalyticsConstants.h; sourceTree = ""; }; 45 | A81DA6E41E89030700B81195 /* SJAnalyticsConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SJAnalyticsConstants.m; sourceTree = ""; }; 46 | A8399C741E85182900396620 /* SJAnalyticsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SJAnalyticsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | A8399C781E85182900396620 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 48 | A8399C7A1E85182900396620 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 49 | A8399C7B1E85182900396620 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 50 | A8399C7D1E85182900396620 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 51 | A8399C7E1E85182900396620 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 52 | A8399C811E85182900396620 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 53 | A8399C831E85182900396620 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 54 | A8399C861E85182900396620 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 55 | A8399C881E85182900396620 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | A8399C8D1E85182900396620 /* SJAnalyticsDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SJAnalyticsDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 57 | A8399C911E85182900396620 /* SJAnalyticsDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SJAnalyticsDemoTests.m; sourceTree = ""; }; 58 | A8399C931E85182900396620 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 59 | A8399C981E85182900396620 /* SJAnalyticsDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SJAnalyticsDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 60 | A8399C9C1E85182900396620 /* SJAnalyticsDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SJAnalyticsDemoUITests.m; sourceTree = ""; }; 61 | A8399C9E1E85182900396620 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 62 | A8399CAB1E8518A400396620 /* SJAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SJAnalytics.h; sourceTree = ""; }; 63 | A8399CAC1E8518A400396620 /* SJAnalytics.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SJAnalytics.m; sourceTree = ""; }; 64 | /* End PBXFileReference section */ 65 | 66 | /* Begin PBXFrameworksBuildPhase section */ 67 | A8399C711E85182800396620 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | A8399C8A1E85182900396620 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | A8399C951E85182900396620 /* Frameworks */ = { 82 | isa = PBXFrameworksBuildPhase; 83 | buildActionMask = 2147483647; 84 | files = ( 85 | ); 86 | runOnlyForDeploymentPostprocessing = 0; 87 | }; 88 | /* End PBXFrameworksBuildPhase section */ 89 | 90 | /* Begin PBXGroup section */ 91 | A8399C6B1E85182800396620 = { 92 | isa = PBXGroup; 93 | children = ( 94 | A8399C761E85182900396620 /* SJAnalyticsDemo */, 95 | A8399C901E85182900396620 /* SJAnalyticsDemoTests */, 96 | A8399C9B1E85182900396620 /* SJAnalyticsDemoUITests */, 97 | A8399C751E85182900396620 /* Products */, 98 | ); 99 | sourceTree = ""; 100 | }; 101 | A8399C751E85182900396620 /* Products */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | A8399C741E85182900396620 /* SJAnalyticsDemo.app */, 105 | A8399C8D1E85182900396620 /* SJAnalyticsDemoTests.xctest */, 106 | A8399C981E85182900396620 /* SJAnalyticsDemoUITests.xctest */, 107 | ); 108 | name = Products; 109 | sourceTree = ""; 110 | }; 111 | A8399C761E85182900396620 /* SJAnalyticsDemo */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | A8399CAA1E8518A400396620 /* codes */, 115 | A8399C7A1E85182900396620 /* AppDelegate.h */, 116 | A8399C7B1E85182900396620 /* AppDelegate.m */, 117 | A8399C7D1E85182900396620 /* ViewController.h */, 118 | A8399C7E1E85182900396620 /* ViewController.m */, 119 | A8399C801E85182900396620 /* Main.storyboard */, 120 | A8399C831E85182900396620 /* Assets.xcassets */, 121 | A8399C851E85182900396620 /* LaunchScreen.storyboard */, 122 | A8399C881E85182900396620 /* Info.plist */, 123 | A8399C771E85182900396620 /* Supporting Files */, 124 | ); 125 | path = SJAnalyticsDemo; 126 | sourceTree = ""; 127 | }; 128 | A8399C771E85182900396620 /* Supporting Files */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | A8399C781E85182900396620 /* main.m */, 132 | ); 133 | name = "Supporting Files"; 134 | sourceTree = ""; 135 | }; 136 | A8399C901E85182900396620 /* SJAnalyticsDemoTests */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | A8399C911E85182900396620 /* SJAnalyticsDemoTests.m */, 140 | A8399C931E85182900396620 /* Info.plist */, 141 | ); 142 | path = SJAnalyticsDemoTests; 143 | sourceTree = ""; 144 | }; 145 | A8399C9B1E85182900396620 /* SJAnalyticsDemoUITests */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | A8399C9C1E85182900396620 /* SJAnalyticsDemoUITests.m */, 149 | A8399C9E1E85182900396620 /* Info.plist */, 150 | ); 151 | path = SJAnalyticsDemoUITests; 152 | sourceTree = ""; 153 | }; 154 | A8399CAA1E8518A400396620 /* codes */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | A8399CAB1E8518A400396620 /* SJAnalytics.h */, 158 | A8399CAC1E8518A400396620 /* SJAnalytics.m */, 159 | A81DA6E21E88F99B00B81195 /* SJAnalyticsProvider.h */, 160 | A81DA6E31E89030700B81195 /* SJAnalyticsConstants.h */, 161 | A81DA6E41E89030700B81195 /* SJAnalyticsConstants.m */, 162 | A81DA6DF1E88EAE500B81195 /* UIApplication+SJAnalytics.h */, 163 | A81DA6E01E88EAE500B81195 /* UIApplication+SJAnalytics.m */, 164 | ); 165 | name = codes; 166 | path = ../../codes; 167 | sourceTree = ""; 168 | }; 169 | /* End PBXGroup section */ 170 | 171 | /* Begin PBXNativeTarget section */ 172 | A8399C731E85182800396620 /* SJAnalyticsDemo */ = { 173 | isa = PBXNativeTarget; 174 | buildConfigurationList = A8399CA11E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemo" */; 175 | buildPhases = ( 176 | A8399C701E85182800396620 /* Sources */, 177 | A8399C711E85182800396620 /* Frameworks */, 178 | A8399C721E85182800396620 /* Resources */, 179 | ); 180 | buildRules = ( 181 | ); 182 | dependencies = ( 183 | ); 184 | name = SJAnalyticsDemo; 185 | productName = SJAnalyticsDemo; 186 | productReference = A8399C741E85182900396620 /* SJAnalyticsDemo.app */; 187 | productType = "com.apple.product-type.application"; 188 | }; 189 | A8399C8C1E85182900396620 /* SJAnalyticsDemoTests */ = { 190 | isa = PBXNativeTarget; 191 | buildConfigurationList = A8399CA41E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemoTests" */; 192 | buildPhases = ( 193 | A8399C891E85182900396620 /* Sources */, 194 | A8399C8A1E85182900396620 /* Frameworks */, 195 | A8399C8B1E85182900396620 /* Resources */, 196 | ); 197 | buildRules = ( 198 | ); 199 | dependencies = ( 200 | A8399C8F1E85182900396620 /* PBXTargetDependency */, 201 | ); 202 | name = SJAnalyticsDemoTests; 203 | productName = SJAnalyticsDemoTests; 204 | productReference = A8399C8D1E85182900396620 /* SJAnalyticsDemoTests.xctest */; 205 | productType = "com.apple.product-type.bundle.unit-test"; 206 | }; 207 | A8399C971E85182900396620 /* SJAnalyticsDemoUITests */ = { 208 | isa = PBXNativeTarget; 209 | buildConfigurationList = A8399CA71E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemoUITests" */; 210 | buildPhases = ( 211 | A8399C941E85182900396620 /* Sources */, 212 | A8399C951E85182900396620 /* Frameworks */, 213 | A8399C961E85182900396620 /* Resources */, 214 | ); 215 | buildRules = ( 216 | ); 217 | dependencies = ( 218 | A8399C9A1E85182900396620 /* PBXTargetDependency */, 219 | ); 220 | name = SJAnalyticsDemoUITests; 221 | productName = SJAnalyticsDemoUITests; 222 | productReference = A8399C981E85182900396620 /* SJAnalyticsDemoUITests.xctest */; 223 | productType = "com.apple.product-type.bundle.ui-testing"; 224 | }; 225 | /* End PBXNativeTarget section */ 226 | 227 | /* Begin PBXProject section */ 228 | A8399C6C1E85182800396620 /* Project object */ = { 229 | isa = PBXProject; 230 | attributes = { 231 | LastUpgradeCheck = 0820; 232 | ORGANIZATIONNAME = jseanj; 233 | TargetAttributes = { 234 | A8399C731E85182800396620 = { 235 | CreatedOnToolsVersion = 8.2.1; 236 | ProvisioningStyle = Automatic; 237 | }; 238 | A8399C8C1E85182900396620 = { 239 | CreatedOnToolsVersion = 8.2.1; 240 | ProvisioningStyle = Automatic; 241 | TestTargetID = A8399C731E85182800396620; 242 | }; 243 | A8399C971E85182900396620 = { 244 | CreatedOnToolsVersion = 8.2.1; 245 | ProvisioningStyle = Automatic; 246 | TestTargetID = A8399C731E85182800396620; 247 | }; 248 | }; 249 | }; 250 | buildConfigurationList = A8399C6F1E85182800396620 /* Build configuration list for PBXProject "SJAnalyticsDemo" */; 251 | compatibilityVersion = "Xcode 3.2"; 252 | developmentRegion = English; 253 | hasScannedForEncodings = 0; 254 | knownRegions = ( 255 | en, 256 | Base, 257 | ); 258 | mainGroup = A8399C6B1E85182800396620; 259 | productRefGroup = A8399C751E85182900396620 /* Products */; 260 | projectDirPath = ""; 261 | projectRoot = ""; 262 | targets = ( 263 | A8399C731E85182800396620 /* SJAnalyticsDemo */, 264 | A8399C8C1E85182900396620 /* SJAnalyticsDemoTests */, 265 | A8399C971E85182900396620 /* SJAnalyticsDemoUITests */, 266 | ); 267 | }; 268 | /* End PBXProject section */ 269 | 270 | /* Begin PBXResourcesBuildPhase section */ 271 | A8399C721E85182800396620 /* Resources */ = { 272 | isa = PBXResourcesBuildPhase; 273 | buildActionMask = 2147483647; 274 | files = ( 275 | A8399C871E85182900396620 /* LaunchScreen.storyboard in Resources */, 276 | A8399C841E85182900396620 /* Assets.xcassets in Resources */, 277 | A8399C821E85182900396620 /* Main.storyboard in Resources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | A8399C8B1E85182900396620 /* Resources */ = { 282 | isa = PBXResourcesBuildPhase; 283 | buildActionMask = 2147483647; 284 | files = ( 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | A8399C961E85182900396620 /* Resources */ = { 289 | isa = PBXResourcesBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | /* End PBXResourcesBuildPhase section */ 296 | 297 | /* Begin PBXSourcesBuildPhase section */ 298 | A8399C701E85182800396620 /* Sources */ = { 299 | isa = PBXSourcesBuildPhase; 300 | buildActionMask = 2147483647; 301 | files = ( 302 | A81DA6E51E89057D00B81195 /* UIApplication+SJAnalytics.m in Sources */, 303 | A8399C7F1E85182900396620 /* ViewController.m in Sources */, 304 | A81DA6E61E89058000B81195 /* SJAnalyticsConstants.m in Sources */, 305 | A8399C7C1E85182900396620 /* AppDelegate.m in Sources */, 306 | A8399C791E85182900396620 /* main.m in Sources */, 307 | A81DA6E71E89058400B81195 /* SJAnalytics.m in Sources */, 308 | ); 309 | runOnlyForDeploymentPostprocessing = 0; 310 | }; 311 | A8399C891E85182900396620 /* Sources */ = { 312 | isa = PBXSourcesBuildPhase; 313 | buildActionMask = 2147483647; 314 | files = ( 315 | A8399C921E85182900396620 /* SJAnalyticsDemoTests.m in Sources */, 316 | ); 317 | runOnlyForDeploymentPostprocessing = 0; 318 | }; 319 | A8399C941E85182900396620 /* Sources */ = { 320 | isa = PBXSourcesBuildPhase; 321 | buildActionMask = 2147483647; 322 | files = ( 323 | A8399C9D1E85182900396620 /* SJAnalyticsDemoUITests.m in Sources */, 324 | ); 325 | runOnlyForDeploymentPostprocessing = 0; 326 | }; 327 | /* End PBXSourcesBuildPhase section */ 328 | 329 | /* Begin PBXTargetDependency section */ 330 | A8399C8F1E85182900396620 /* PBXTargetDependency */ = { 331 | isa = PBXTargetDependency; 332 | target = A8399C731E85182800396620 /* SJAnalyticsDemo */; 333 | targetProxy = A8399C8E1E85182900396620 /* PBXContainerItemProxy */; 334 | }; 335 | A8399C9A1E85182900396620 /* PBXTargetDependency */ = { 336 | isa = PBXTargetDependency; 337 | target = A8399C731E85182800396620 /* SJAnalyticsDemo */; 338 | targetProxy = A8399C991E85182900396620 /* PBXContainerItemProxy */; 339 | }; 340 | /* End PBXTargetDependency section */ 341 | 342 | /* Begin PBXVariantGroup section */ 343 | A8399C801E85182900396620 /* Main.storyboard */ = { 344 | isa = PBXVariantGroup; 345 | children = ( 346 | A8399C811E85182900396620 /* Base */, 347 | ); 348 | name = Main.storyboard; 349 | sourceTree = ""; 350 | }; 351 | A8399C851E85182900396620 /* LaunchScreen.storyboard */ = { 352 | isa = PBXVariantGroup; 353 | children = ( 354 | A8399C861E85182900396620 /* Base */, 355 | ); 356 | name = LaunchScreen.storyboard; 357 | sourceTree = ""; 358 | }; 359 | /* End PBXVariantGroup section */ 360 | 361 | /* Begin XCBuildConfiguration section */ 362 | A8399C9F1E85182900396620 /* Debug */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_ANALYZER_NONNULL = YES; 367 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 368 | CLANG_CXX_LIBRARY = "libc++"; 369 | CLANG_ENABLE_MODULES = YES; 370 | CLANG_ENABLE_OBJC_ARC = YES; 371 | CLANG_WARN_BOOL_CONVERSION = YES; 372 | CLANG_WARN_CONSTANT_CONVERSION = YES; 373 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 374 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 375 | CLANG_WARN_EMPTY_BODY = YES; 376 | CLANG_WARN_ENUM_CONVERSION = YES; 377 | CLANG_WARN_INFINITE_RECURSION = YES; 378 | CLANG_WARN_INT_CONVERSION = YES; 379 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 380 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = dwarf; 386 | ENABLE_STRICT_OBJC_MSGSEND = YES; 387 | ENABLE_TESTABILITY = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu99; 389 | GCC_DYNAMIC_NO_PIC = NO; 390 | GCC_NO_COMMON_BLOCKS = YES; 391 | GCC_OPTIMIZATION_LEVEL = 0; 392 | GCC_PREPROCESSOR_DEFINITIONS = ( 393 | "DEBUG=1", 394 | "$(inherited)", 395 | ); 396 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 397 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 398 | GCC_WARN_UNDECLARED_SELECTOR = YES; 399 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 400 | GCC_WARN_UNUSED_FUNCTION = YES; 401 | GCC_WARN_UNUSED_VARIABLE = YES; 402 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 403 | MTL_ENABLE_DEBUG_INFO = YES; 404 | ONLY_ACTIVE_ARCH = YES; 405 | SDKROOT = iphoneos; 406 | TARGETED_DEVICE_FAMILY = "1,2"; 407 | }; 408 | name = Debug; 409 | }; 410 | A8399CA01E85182900396620 /* Release */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | ALWAYS_SEARCH_USER_PATHS = NO; 414 | CLANG_ANALYZER_NONNULL = YES; 415 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 416 | CLANG_CXX_LIBRARY = "libc++"; 417 | CLANG_ENABLE_MODULES = YES; 418 | CLANG_ENABLE_OBJC_ARC = YES; 419 | CLANG_WARN_BOOL_CONVERSION = YES; 420 | CLANG_WARN_CONSTANT_CONVERSION = YES; 421 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 422 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 423 | CLANG_WARN_EMPTY_BODY = YES; 424 | CLANG_WARN_ENUM_CONVERSION = YES; 425 | CLANG_WARN_INFINITE_RECURSION = YES; 426 | CLANG_WARN_INT_CONVERSION = YES; 427 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 428 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 429 | CLANG_WARN_UNREACHABLE_CODE = YES; 430 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 431 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 432 | COPY_PHASE_STRIP = NO; 433 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 434 | ENABLE_NS_ASSERTIONS = NO; 435 | ENABLE_STRICT_OBJC_MSGSEND = YES; 436 | GCC_C_LANGUAGE_STANDARD = gnu99; 437 | GCC_NO_COMMON_BLOCKS = YES; 438 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 439 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 440 | GCC_WARN_UNDECLARED_SELECTOR = YES; 441 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 442 | GCC_WARN_UNUSED_FUNCTION = YES; 443 | GCC_WARN_UNUSED_VARIABLE = YES; 444 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 445 | MTL_ENABLE_DEBUG_INFO = NO; 446 | SDKROOT = iphoneos; 447 | TARGETED_DEVICE_FAMILY = "1,2"; 448 | VALIDATE_PRODUCT = YES; 449 | }; 450 | name = Release; 451 | }; 452 | A8399CA21E85182900396620 /* Debug */ = { 453 | isa = XCBuildConfiguration; 454 | buildSettings = { 455 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 456 | INFOPLIST_FILE = SJAnalyticsDemo/Info.plist; 457 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 458 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemo; 459 | PRODUCT_NAME = "$(TARGET_NAME)"; 460 | }; 461 | name = Debug; 462 | }; 463 | A8399CA31E85182900396620 /* Release */ = { 464 | isa = XCBuildConfiguration; 465 | buildSettings = { 466 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 467 | INFOPLIST_FILE = SJAnalyticsDemo/Info.plist; 468 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 469 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemo; 470 | PRODUCT_NAME = "$(TARGET_NAME)"; 471 | }; 472 | name = Release; 473 | }; 474 | A8399CA51E85182900396620 /* Debug */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | BUNDLE_LOADER = "$(TEST_HOST)"; 478 | INFOPLIST_FILE = SJAnalyticsDemoTests/Info.plist; 479 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 480 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemoTests; 481 | PRODUCT_NAME = "$(TARGET_NAME)"; 482 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SJAnalyticsDemo.app/SJAnalyticsDemo"; 483 | }; 484 | name = Debug; 485 | }; 486 | A8399CA61E85182900396620 /* Release */ = { 487 | isa = XCBuildConfiguration; 488 | buildSettings = { 489 | BUNDLE_LOADER = "$(TEST_HOST)"; 490 | INFOPLIST_FILE = SJAnalyticsDemoTests/Info.plist; 491 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 492 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemoTests; 493 | PRODUCT_NAME = "$(TARGET_NAME)"; 494 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SJAnalyticsDemo.app/SJAnalyticsDemo"; 495 | }; 496 | name = Release; 497 | }; 498 | A8399CA81E85182900396620 /* Debug */ = { 499 | isa = XCBuildConfiguration; 500 | buildSettings = { 501 | INFOPLIST_FILE = SJAnalyticsDemoUITests/Info.plist; 502 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 503 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemoUITests; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | TEST_TARGET_NAME = SJAnalyticsDemo; 506 | }; 507 | name = Debug; 508 | }; 509 | A8399CA91E85182900396620 /* Release */ = { 510 | isa = XCBuildConfiguration; 511 | buildSettings = { 512 | INFOPLIST_FILE = SJAnalyticsDemoUITests/Info.plist; 513 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 514 | PRODUCT_BUNDLE_IDENTIFIER = com.knewcloud.SJAnalyticsDemoUITests; 515 | PRODUCT_NAME = "$(TARGET_NAME)"; 516 | TEST_TARGET_NAME = SJAnalyticsDemo; 517 | }; 518 | name = Release; 519 | }; 520 | /* End XCBuildConfiguration section */ 521 | 522 | /* Begin XCConfigurationList section */ 523 | A8399C6F1E85182800396620 /* Build configuration list for PBXProject "SJAnalyticsDemo" */ = { 524 | isa = XCConfigurationList; 525 | buildConfigurations = ( 526 | A8399C9F1E85182900396620 /* Debug */, 527 | A8399CA01E85182900396620 /* Release */, 528 | ); 529 | defaultConfigurationIsVisible = 0; 530 | defaultConfigurationName = Release; 531 | }; 532 | A8399CA11E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemo" */ = { 533 | isa = XCConfigurationList; 534 | buildConfigurations = ( 535 | A8399CA21E85182900396620 /* Debug */, 536 | A8399CA31E85182900396620 /* Release */, 537 | ); 538 | defaultConfigurationIsVisible = 0; 539 | defaultConfigurationName = Release; 540 | }; 541 | A8399CA41E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemoTests" */ = { 542 | isa = XCConfigurationList; 543 | buildConfigurations = ( 544 | A8399CA51E85182900396620 /* Debug */, 545 | A8399CA61E85182900396620 /* Release */, 546 | ); 547 | defaultConfigurationIsVisible = 0; 548 | defaultConfigurationName = Release; 549 | }; 550 | A8399CA71E85182900396620 /* Build configuration list for PBXNativeTarget "SJAnalyticsDemoUITests" */ = { 551 | isa = XCConfigurationList; 552 | buildConfigurations = ( 553 | A8399CA81E85182900396620 /* Debug */, 554 | A8399CA91E85182900396620 /* Release */, 555 | ); 556 | defaultConfigurationIsVisible = 0; 557 | defaultConfigurationName = Release; 558 | }; 559 | /* End XCConfigurationList section */ 560 | }; 561 | rootObject = A8399C6C1E85182800396620 /* Project object */; 562 | } 563 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SJAnalyticsDemo 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SJAnalyticsDemo 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | #import "SJAnalytics.h" 12 | 13 | @interface AppDelegate () 14 | 15 | @end 16 | 17 | @implementation AppDelegate 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 21 | // Override point for customization after application launch. 22 | 23 | [[SJAnalytics shared] configure: 24 | @{ 25 | SJAnalyticsMethodCall: @[ 26 | @{ 27 | SJAnalyticsClass:ViewController.class, 28 | SJAnalyticsDetails: @[ 29 | @{ 30 | SJAnalyticsEvent: @"testNoParamsEvent", 31 | SJAnalyticsSelector: NSStringFromSelector(@selector(testNoParams)), 32 | SJAnalyticsShouldExecute:^BOOL(ViewController *instance, NSArray *params) { 33 | return NO; 34 | }, 35 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 36 | return @{}; 37 | } 38 | }, 39 | @{ 40 | SJAnalyticsEvent: @"testParamsEvent", 41 | SJAnalyticsSelector: NSStringFromSelector(@selector(testParams:)), 42 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 43 | return @{}; 44 | } 45 | }, 46 | @{ 47 | SJAnalyticsEvent: @"testBlockSuccessEvent", 48 | SJAnalyticsSelector: NSStringFromSelector(@selector(testBlockSuccess:failure:)), 49 | SJAnalyticsShouldExecute:^BOOL(ViewController *instance, NSArray *params) { 50 | if ([params[0] isKindOfClass:[NSNull class]]) { 51 | return NO; 52 | } else { 53 | return YES; 54 | } 55 | }, 56 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 57 | return @{}; 58 | } 59 | } 60 | ] 61 | } 62 | ], 63 | SJAnalyticsUIControl: @[ 64 | @{ 65 | SJAnalyticsClass:ViewController.class, 66 | SJAnalyticsDetails: @[ 67 | @{ 68 | SJAnalyticsEvent: @"btnTappedEvent", 69 | SJAnalyticsSelector: @"btnTapped:", 70 | SJAnalyticsParameters:^NSDictionary*(ViewController *instance, NSArray *params) { 71 | return @{}; 72 | } 73 | } 74 | ] 75 | } 76 | ] 77 | } provider:self]; 78 | 79 | return YES; 80 | } 81 | 82 | #pragma mark - SJAnalyticsProvider 83 | - (void)event:(NSString *)event withParameters:(NSDictionary *)parameters { 84 | NSLog(@"event: %@, and parameters: %@", event, parameters); 85 | } 86 | 87 | 88 | - (void)applicationWillResignActive:(UIApplication *)application { 89 | // 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. 90 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 91 | } 92 | 93 | 94 | - (void)applicationDidEnterBackground:(UIApplication *)application { 95 | // 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. 96 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 97 | } 98 | 99 | 100 | - (void)applicationWillEnterForeground:(UIApplication *)application { 101 | // 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. 102 | } 103 | 104 | 105 | - (void)applicationDidBecomeActive:(UIApplication *)application { 106 | // 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. 107 | } 108 | 109 | 110 | - (void)applicationWillTerminate:(UIApplication *)application { 111 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 112 | } 113 | 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/Assets.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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/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 | 27 | 28 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/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 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SJAnalyticsDemo 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | - (void)testNoParams; 14 | - (void)testParams:(NSString *)param; 15 | - (void)testBlockSuccess:(void(^)())success failure:(void(^)())failure; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SJAnalyticsDemo 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | 21 | // SJAnalyticsMethodCall 22 | [self testNoParams]; 23 | [self testParams:@"test"]; 24 | [self testBlockSuccess:^{ 25 | NSLog(@"success"); 26 | } failure:^{ 27 | NSLog(@"failure"); 28 | }]; 29 | 30 | // SJAnalyticsUIControl 31 | 32 | } 33 | 34 | - (void)testNoParams { 35 | NSLog(@"testNoParams"); 36 | } 37 | 38 | - (void)testParams:(NSString *)param { 39 | NSLog(@"testParams: %@", param); 40 | } 41 | 42 | - (void)testBlockSuccess:(void(^)())success failure:(void(^)())failure { 43 | NSLog(@"testBlock"); 44 | if (success) { 45 | success(); 46 | } 47 | if (failure) { 48 | failure(); 49 | } 50 | } 51 | 52 | - (IBAction)btnTapped:(id)sender { 53 | NSLog(@"btnTapped"); 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SJAnalyticsDemo 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemoTests/SJAnalyticsDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SJAnalyticsDemoTests.m 3 | // SJAnalyticsDemoTests 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SJAnalyticsDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SJAnalyticsDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /SJAnalyticsDemo/SJAnalyticsDemoUITests/SJAnalyticsDemoUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SJAnalyticsDemoUITests.m 3 | // SJAnalyticsDemoUITests 4 | // 5 | // Created by knewcloud on 2017/3/24. 6 | // Copyright © 2017年 jseanj. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SJAnalyticsDemoUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SJAnalyticsDemoUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /codes/SJAnalytics.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "SJAnalyticsProvider.h" 3 | #import "SJAnalyticsConstants.h" 4 | 5 | @interface SJAnalytics : NSObject 6 | @property (nonatomic, strong) id provider; 7 | + (instancetype)shared; 8 | - (void)configure:(NSDictionary *)configurationDictionary provider:(id)provider; 9 | @end 10 | -------------------------------------------------------------------------------- /codes/SJAnalytics.m: -------------------------------------------------------------------------------- 1 | #import "SJAnalytics.h" 2 | #import 3 | #import 4 | #import "UIApplication+SJAnalytics.h" 5 | 6 | static NSMutableDictionary *eventDetails() { 7 | static NSMutableDictionary *dict; 8 | static dispatch_once_t onceToken; 9 | dispatch_once(&onceToken, ^{ 10 | dict = [[NSMutableDictionary alloc] init]; 11 | }); 12 | return dict; 13 | } 14 | 15 | static NSMutableDictionary *selectorEvents() { 16 | static NSMutableDictionary *dict; 17 | static dispatch_once_t onceToken; 18 | dispatch_once(&onceToken, ^{ 19 | dict = [[NSMutableDictionary alloc] init]; 20 | }); 21 | return dict; 22 | } 23 | 24 | static void sj_swizzSelector(Class class, SEL swizzledSelector, SEL originalSelector) { 25 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 26 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 27 | BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); 28 | if (success) { 29 | class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); 30 | } else { 31 | method_exchangeImplementations(originalMethod, swizzledMethod); 32 | } 33 | } 34 | 35 | static SEL sj_selectorForOriginSelector(SEL selector) { 36 | return NSSelectorFromString([NSStringFromSelector(selector) stringByAppendingString:@"__sj"]); 37 | } 38 | 39 | static NSString *sj_strForClassAndSelector(Class klass, SEL selector) { 40 | return [NSString stringWithFormat:@"%@_%@", NSStringFromClass(klass), NSStringFromSelector(selector)]; 41 | } 42 | 43 | static NSArray *sj_parametersForInvocation(NSInvocation *invocation) { 44 | NSMethodSignature *methodSignature = [invocation methodSignature]; 45 | NSInteger numberOfArguments = [methodSignature numberOfArguments]; 46 | NSMutableArray *argumentsArray = [NSMutableArray arrayWithCapacity:numberOfArguments - 2]; 47 | for (NSUInteger index = 2; index < numberOfArguments; index++) { 48 | const char *argumentType = [methodSignature getArgumentTypeAtIndex:index]; 49 | #define WRAP_AND_RETURN(type) \ 50 | do { \ 51 | type val = 0; \ 52 | [invocation getArgument:&val atIndex:(NSInteger)index]; \ 53 | [argumentsArray addObject:@(val)]; \ 54 | } while (0) 55 | if (strcmp(argumentType, @encode(id)) == 0 || strcmp(argumentType, @encode(Class)) == 0) { 56 | __autoreleasing id returnObj; 57 | [invocation getArgument:&returnObj atIndex:(NSInteger)index]; 58 | [argumentsArray addObject:returnObj]; 59 | } else if (strcmp(argumentType, @encode(char)) == 0) { 60 | WRAP_AND_RETURN(char); 61 | } else if (strcmp(argumentType, @encode(int)) == 0) { 62 | WRAP_AND_RETURN(int); 63 | } else if (strcmp(argumentType, @encode(short)) == 0) { 64 | WRAP_AND_RETURN(short); 65 | } else if (strcmp(argumentType, @encode(long)) == 0) { 66 | WRAP_AND_RETURN(long); 67 | } else if (strcmp(argumentType, @encode(long long)) == 0) { 68 | WRAP_AND_RETURN(long long); 69 | } else if (strcmp(argumentType, @encode(unsigned char)) == 0) { 70 | WRAP_AND_RETURN(unsigned char); 71 | } else if (strcmp(argumentType, @encode(unsigned int)) == 0) { 72 | WRAP_AND_RETURN(unsigned int); 73 | } else if (strcmp(argumentType, @encode(unsigned short)) == 0) { 74 | WRAP_AND_RETURN(unsigned short); 75 | } else if (strcmp(argumentType, @encode(unsigned long)) == 0) { 76 | WRAP_AND_RETURN(unsigned long); 77 | } else if (strcmp(argumentType, @encode(unsigned long long)) == 0) { 78 | WRAP_AND_RETURN(unsigned long long); 79 | } else if (strcmp(argumentType, @encode(float)) == 0) { 80 | WRAP_AND_RETURN(float); 81 | } else if (strcmp(argumentType, @encode(double)) == 0) { 82 | WRAP_AND_RETURN(double); 83 | } else if (strcmp(argumentType, @encode(BOOL)) == 0) { 84 | WRAP_AND_RETURN(BOOL); 85 | } else if (strcmp(argumentType, @encode(char *)) == 0) { 86 | WRAP_AND_RETURN(const char *); 87 | } else if (strcmp(argumentType, @encode(void (^)(void))) == 0) { 88 | __unsafe_unretained id block = nil; 89 | [invocation getArgument:&block atIndex:(NSInteger)index]; 90 | if (block) { 91 | [argumentsArray addObject:[block copy]]; 92 | } else { 93 | [argumentsArray addObject:[NSNull null]]; 94 | } 95 | } else { 96 | NSUInteger valueSize = 0; 97 | NSGetSizeAndAlignment(argumentType, &valueSize, NULL); 98 | 99 | unsigned char valueBytes[valueSize]; 100 | [invocation getArgument:valueBytes atIndex:(NSInteger)index]; 101 | 102 | [argumentsArray addObject:[NSValue valueWithBytes:valueBytes objCType:argumentType]]; 103 | } 104 | } 105 | return [argumentsArray copy]; 106 | } 107 | 108 | static void SJForwardInvocation(__unsafe_unretained id assignSlf, SEL selector, NSInvocation *invocation) { 109 | NSArray *events = selectorEvents()[sj_strForClassAndSelector([assignSlf class], invocation.selector)]; 110 | [events enumerateObjectsUsingBlock:^(NSString *eventName, NSUInteger idx, BOOL *stop) { 111 | NSDictionary *detail = eventDetails()[eventName]; 112 | NSArray *argumentsArray = sj_parametersForInvocation(invocation); 113 | BOOL (^shouldExecuteBlock)(id object, NSArray *parameters) = detail[SJAnalyticsShouldExecute]; 114 | NSDictionary *(^parametersBlock)(id object, NSArray *parameters) = detail[SJAnalyticsParameters]; 115 | if (shouldExecuteBlock == nil || shouldExecuteBlock(assignSlf, argumentsArray)) { 116 | [[SJAnalytics shared].provider event:eventName withParameters:parametersBlock(assignSlf, argumentsArray)]; 117 | } 118 | }]; 119 | SEL newSelector = sj_selectorForOriginSelector(invocation.selector); 120 | invocation.selector = newSelector; 121 | [invocation invoke]; 122 | } 123 | 124 | @implementation SJAnalytics 125 | 126 | + (instancetype)shared { 127 | static SJAnalytics *analytics; 128 | static dispatch_once_t onceToken; 129 | dispatch_once(&onceToken, ^{ 130 | analytics = [[SJAnalytics alloc] init]; 131 | }); 132 | return analytics; 133 | } 134 | 135 | - (void)configure:(NSDictionary *)configurationDictionary provider:(id)provider { 136 | self.provider = provider; 137 | NSArray *trackedMethodCallEventClasses = configurationDictionary[SJAnalyticsMethodCall]; 138 | [trackedMethodCallEventClasses enumerateObjectsUsingBlock:^(NSDictionary *eventDictionary, NSUInteger idx, BOOL *stop) { 139 | [self __addMethodCallEventAnalyticsHook:eventDictionary]; 140 | }]; 141 | NSArray *trackedUIControlEventClasses = configurationDictionary[SJAnalyticsUIControl]; 142 | if (trackedUIControlEventClasses.count) { 143 | sj_swizzSelector([UIApplication class], @selector(sj_sendAction:to:from:forEvent:), @selector(sendAction:to:from:forEvent:)); 144 | [UIApplication sharedApplication].provider = self.provider; 145 | } 146 | [trackedUIControlEventClasses enumerateObjectsUsingBlock:^(NSDictionary *eventDictionary, NSUInteger idx, BOOL *stop) { 147 | [self __addUIControlEventAnalyticsHook:eventDictionary]; 148 | }]; 149 | } 150 | 151 | - (void)__addMethodCallEventAnalyticsHook:(NSDictionary *)eventDictionary { 152 | Class klass = eventDictionary[SJAnalyticsClass]; 153 | [eventDictionary[SJAnalyticsDetails] enumerateObjectsUsingBlock:^(id dict, NSUInteger idx, BOOL *stop) { 154 | NSString *selectorName = dict[SJAnalyticsSelector]; 155 | SEL originSelector = NSSelectorFromString(selectorName); 156 | Method originMethod = class_getInstanceMethod(klass, originSelector); 157 | const char *typeEncoding = method_getTypeEncoding(originMethod); 158 | 159 | SEL newSelector = sj_selectorForOriginSelector(originSelector); 160 | class_addMethod(klass, newSelector, method_getImplementation(originMethod), typeEncoding); 161 | 162 | class_replaceMethod(klass, originSelector, _objc_msgForward, typeEncoding); 163 | 164 | if (class_getMethodImplementation(klass, @selector(forwardInvocation:)) != (IMP)SJForwardInvocation) { 165 | class_replaceMethod(klass, @selector(forwardInvocation:), (IMP)SJForwardInvocation, "v@:@"); 166 | } 167 | 168 | NSMutableDictionary *detailDict = [dict mutableCopy]; 169 | [detailDict removeObjectForKey:SJAnalyticsEvent]; 170 | [eventDetails() setObject:detailDict forKey:dict[SJAnalyticsEvent]]; 171 | 172 | NSString *selectorKey = sj_strForClassAndSelector(klass, originSelector); 173 | NSMutableArray *events = selectorEvents()[selectorKey]; 174 | if (!events) events = [NSMutableArray new]; 175 | [events addObject:dict[SJAnalyticsEvent]]; 176 | [selectorEvents() setObject:events forKey:selectorKey]; 177 | }]; 178 | } 179 | 180 | - (void)__addUIControlEventAnalyticsHook:(NSDictionary *)eventDictionary { 181 | Class klass = eventDictionary[SJAnalyticsClass]; 182 | [eventDictionary[SJAnalyticsDetails] enumerateObjectsUsingBlock:^(id dict, NSUInteger idx, BOOL *stop) { 183 | NSString *selectorName = dict[SJAnalyticsSelector]; 184 | SEL originSelector = NSSelectorFromString(selectorName); 185 | 186 | NSMutableDictionary *detailDict = [dict mutableCopy]; 187 | [detailDict removeObjectForKey:SJAnalyticsEvent]; 188 | [[UIApplication sharedApplication].eventDetails setObject:detailDict forKey:dict[SJAnalyticsEvent]]; 189 | 190 | NSString *selectorKey = sj_strForClassAndSelector(klass, originSelector); 191 | NSMutableArray *events = [UIApplication sharedApplication].selectorEvents[selectorKey]; 192 | if (!events) events = [NSMutableArray new]; 193 | [events addObject:dict[SJAnalyticsEvent]]; 194 | [[UIApplication sharedApplication].selectorEvents setObject:events forKey:selectorKey]; 195 | }]; 196 | } 197 | 198 | @end 199 | -------------------------------------------------------------------------------- /codes/SJAnalyticsConstants.h: -------------------------------------------------------------------------------- 1 | #import 2 | extern NSString * const SJAnalyticsMethodCall; 3 | extern NSString * const SJAnalyticsUIControl; 4 | extern NSString * const SJAnalyticsClass; 5 | extern NSString * const SJAnalyticsSelector; 6 | extern NSString * const SJAnalyticsDetails; 7 | extern NSString * const SJAnalyticsParameters; 8 | extern NSString * const SJAnalyticsShouldExecute; 9 | extern NSString * const SJAnalyticsEvent; 10 | -------------------------------------------------------------------------------- /codes/SJAnalyticsConstants.m: -------------------------------------------------------------------------------- 1 | #import "SJAnalyticsConstants.h" 2 | NSString * const SJAnalyticsMethodCall = @"methodCall"; 3 | NSString * const SJAnalyticsUIControl = @"UIControl"; 4 | NSString * const SJAnalyticsClass = @"class"; 5 | NSString * const SJAnalyticsSelector = @"selector"; 6 | NSString * const SJAnalyticsDetails = @"details"; 7 | NSString * const SJAnalyticsParameters = @"parameters"; 8 | NSString * const SJAnalyticsShouldExecute = @"shouldExecute"; 9 | NSString * const SJAnalyticsEvent = @"event"; 10 | -------------------------------------------------------------------------------- /codes/SJAnalyticsProvider.h: -------------------------------------------------------------------------------- 1 | #import 2 | @protocol SJAnalyticsProvider 3 | - (void)event:(NSString *)event withParameters:(NSDictionary *)parameters; 4 | @end 5 | -------------------------------------------------------------------------------- /codes/UIApplication+SJAnalytics.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "SJAnalyticsProvider.h" 3 | 4 | @interface UIApplication (SJAnalytics) 5 | @property (nonatomic, strong) id provider; 6 | @property (nonatomic, strong) NSMutableDictionary *eventDetails; 7 | @property (nonatomic, strong) NSMutableDictionary *selectorEvents; 8 | - (BOOL)sj_sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event; 9 | @end 10 | -------------------------------------------------------------------------------- /codes/UIApplication+SJAnalytics.m: -------------------------------------------------------------------------------- 1 | #import "UIApplication+SJAnalytics.h" 2 | #import 3 | #import "SJAnalyticsConstants.h" 4 | 5 | static int const SJAnalyticsProviderKey; 6 | static int const SJAnalyticsEventDetailsKey; 7 | static int const SJAnalyticsSelectorEventsKey; 8 | 9 | static NSString *sj_controlStrForClassAndSelector(Class klass, SEL selector) { 10 | return [NSString stringWithFormat:@"%@_%@", NSStringFromClass(klass), NSStringFromSelector(selector)]; 11 | } 12 | 13 | @implementation UIApplication (SJAnalytics) 14 | 15 | - (id)provider{ 16 | return objc_getAssociatedObject(self, &SJAnalyticsProviderKey); 17 | } 18 | 19 | - (void)setProvider:(id)provider { 20 | objc_setAssociatedObject(self, &SJAnalyticsProviderKey, provider, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 21 | } 22 | 23 | - (NSMutableDictionary *)eventDetails { 24 | NSMutableDictionary *dict = objc_getAssociatedObject(self, &SJAnalyticsEventDetailsKey); 25 | 26 | if (dict == nil) { 27 | dict = [NSMutableDictionary new]; 28 | objc_setAssociatedObject(self, &SJAnalyticsEventDetailsKey, dict, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 29 | } 30 | 31 | return dict; 32 | } 33 | 34 | - (void)setEventDetails:(NSMutableDictionary *)eventDetails { 35 | objc_setAssociatedObject(self, &SJAnalyticsEventDetailsKey, eventDetails, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 36 | } 37 | 38 | - (NSMutableDictionary *)selectorEvents { 39 | NSMutableDictionary *dict = objc_getAssociatedObject(self, &SJAnalyticsSelectorEventsKey); 40 | 41 | if (dict == nil) { 42 | dict = [NSMutableDictionary new]; 43 | objc_setAssociatedObject(self, &SJAnalyticsSelectorEventsKey, dict, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 44 | } 45 | 46 | return dict; 47 | } 48 | 49 | - (void)setSelectorEvents:(NSMutableDictionary *)selectorEvents { 50 | objc_setAssociatedObject(self, &SJAnalyticsSelectorEventsKey, selectorEvents, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 51 | } 52 | 53 | - (BOOL)sj_sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event { 54 | NSArray *events = self.selectorEvents[sj_controlStrForClassAndSelector([target class], action)]; 55 | [events enumerateObjectsUsingBlock:^(NSString *eventName, NSUInteger idx, BOOL *stop) { 56 | NSDictionary *detail = self.eventDetails[eventName]; 57 | BOOL (^shouldExecuteBlock)(id object, NSArray *parameters) = detail[SJAnalyticsShouldExecute]; 58 | NSDictionary *(^parametersBlock)(id object, NSArray *parameters) = detail[SJAnalyticsParameters]; 59 | if (shouldExecuteBlock == nil || shouldExecuteBlock(target, @[])) { 60 | [self.provider event:eventName withParameters:parametersBlock(target, @[])]; 61 | } 62 | }]; 63 | 64 | return [self sj_sendAction:action to:target from:sender forEvent:event]; 65 | } 66 | @end 67 | --------------------------------------------------------------------------------