{"_id":"561ae15563ef571900ca68d9","version":{"_id":"561ae15463ef571900ca68d6","project":"561ae15363ef571900ca68d3","__v":3,"createdAt":"2015-10-11T22:23:16.492Z","releaseDate":"2015-10-11T22:23:16.492Z","categories":["561ae15563ef571900ca68d7","56255c864dcb400d00ff4427","56326faf45f2cb0d006be3f1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"561ae15563ef571900ca68d7","version":"561ae15463ef571900ca68d6","pages":["561ae15563ef571900ca68d9","561af2911a10ea0d002387f7","561af4a878436c19009e87d8","561c3b3400e13c0d00936286","56327cdb38f8aa0d00d30f6e","566b532068eba90d009cac6c","5672df821e18b60d00b04a32"],"project":"561ae15363ef571900ca68d3","__v":7,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-11T22:23:17.043Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"__v":45,"user":"561ae13963ef571900ca68d2","githubsync":"","project":"561ae15363ef571900ca68d3","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-11T22:23:17.852Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"This section contains documentation for configuring the AppHub SDKs from native code.\n\n---\n\n## Native and JavaScript components\n\nAll AppHub developers should understand the distinction between React Native \"native components\" and JavaScript components. Every React Native application contains both native code (Objective-C/Java) and JavaScript. You will likely be making most of your changes to JavaScript code, and you will make occasional modifications to native code.\n\nAppHub allows you to push JavaScript and image updates to your users. **If you make breaking changes to native code, you must update your application via Apple/Google**.\n\nWe recommend that you test your AppHub builds with their associated native code versions\nbefore deploying to your users. Check out the [debug builds section](http://docs.apphub.io/v1.0/docs/getting-started#section-debug-builds) for information on how to test builds with test users.\n\n---\n\n## Logging\n\nFor debugging purposes, it can often be helpful to enable verbose logging mode:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[AppHub setLogLevel:AHLogLevelDebug];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.setLogLevel(.Debug);\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"AppHub.setLogLevel(AppHubLogLevel.Debug);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n## Network Usage\n\nThe AppHub SDK polls for new builds of your app and downloads new builds in a background thread.\n\nBy default, the AppHub SDK will only poll for new builds when the device is connected to WiFi.\n\nYou can permit the SDK to download new builds on a cellular connection (WWAN) like so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[AppHub buildManager].cellularDownloadsEnabled = YES;\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.buildManager().cellularDownloadsEnabled = true\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().setCellularDownloadsEnabled(true);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n---\n\n## Listening for New Builds\n\nIf you want to perform an action when a new build becomes available to your application, such as displaying an alert to the user or force refreshing the app, you can listen for new build events.\n\nYou can register a listener for this event like so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import \\\"AppHub.h\\\"\\n\\n...\\n  \\n- (instancetype)init\\n{\\n    if ((self = [super init])) {\\n        [[NSNotificationCenter defaultCenter] \\n                   addObserver:self \\n                      selector::::at:::selector(buildManagerDidMakeBuildAvailable:) \\n                          name:AHBuildManagerDidMakeBuildAvailableNotification \\n                        object:nil];\\n    }\\n    \\n    return self;\\n}\\n\\n...\\n  \\n- (void)buildManagerDidMakeBuildAvailable:(NSNotification *)notification\\n{\\n    AHBuild *build = notification.userInfo[AHBuildManagerBuildKey];\\n    // Do something with the new build...\\n}\\n\\n...\\n  \\n- (void)dealloc\\n{\\n    [[NSNotificationCenter defaultCenter] removeObserver:self];\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"class AppHubModule {\\n  init() {\\n    NSNotificationCenter.defaultCenter().addObserver(self, selector: \\\"buildManagerDidMakeBuildAvailable:\\\", name: AHBuildManagerDidMakeBuildAvailableNotification, object: nil)\\n  }\\n  \\n  @objc private func buildManagerDidMakeBuildAvailable(notification: NSNotification){\\n    let build = notification.userInfo![AHBuildManagerBuildKey] as! AHBuild;\\n    // Do something with the build, like show an alert to the user.\\n  }\\n  \\n  deinit {\\n    NSNotificationCenter.defaultCenter().removeObserver(self)\\n  }\\n}\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().addNewBuildListener(new AppHubNewBuildListener() {\\n\\t\\t@Override\\n    public void onNewBuild(AppHubBuild build) {\\n\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n---\n\n## Debug Builds\n\nMany developers use AppHub with testing services like TestFlight and HockeyApp as it is desirable to push AppHub updates to your beta users before pushing them to production.\n\nTo enable \"debug\" builds, enable this property in your Objective-C code and distribute to beta users:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[AppHub buildManager].debugBuildsEnabled = YES;\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.buildManager().debugBuildsEnabled = true\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().setDebugBuildsEnabled(true);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nWhen deploying builds from the AppHub dashboard, configure your build to deploy to the \"debug\" target. [See the dashboard docs for more information](http://docs.apphub.io/docs/using-the-dashboard#section-uploading-builds).\n\n---\n\n## Polling for New Builds (Advanced)\n\nThe AppHub SDK will poll our servers for new builds of your App.\n\nIf you wish to manually control the frequency and timing of the polling, you can disable automatic polling:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[AppHub buildManager].automaticPollingEnabled = NO;\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.buildManager().automaticPollingEnabled = false\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().setAutomaticPollingEnabled(false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo poll for new builds, call this method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AppHub buildManager] fetchBuildWithCompletionHandler:nil];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.buildManager().fetchBuildWithCompletionHandler(nil)\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().fetchBuild(null);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThis method can also take a completion block as an argument:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AppHub buildManager] fetchBuildWithCompletionHandler: ^(AHBuild *result, NSError *error) {\\n   // If the `result` AHBuild is not nil, then it is guaranteed\\n   // to be the most up-to-date build of the app.\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"AppHub.buildManager().fetchBuildWithCompletionHandler {(result: AHBuild, error: NSError) -> Void in\\n    // If the `result` AHBuild is not nil, then it is guaranteed\\n    // to be the most up-to-date build of the app.\\n}\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"application.getBuildManager().fetchBuild(new FetchBuildCallback() {\\n\\t\\t@Override\\n\\t\\tpublic void done(AppHubBuild build, AppHubException e) {\\n    \\t\\t// If the `build` is not nil, then it is guaranteed\\n    \\t\\t// to be the most up-to-date build of the app.\\n\\t\\t}\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSome developers choose to use this method at startup to ensure that all devices have the most up-to-date build.","excerpt":"Configuring and extending the AppHub SDK.","slug":"getting-started","type":"basic","title":"Configuration (Native SDKs)"}

Configuration (Native SDKs)

Configuring and extending the AppHub SDK.

This section contains documentation for configuring the AppHub SDKs from native code. --- ## Native and JavaScript components All AppHub developers should understand the distinction between React Native "native components" and JavaScript components. Every React Native application contains both native code (Objective-C/Java) and JavaScript. You will likely be making most of your changes to JavaScript code, and you will make occasional modifications to native code. AppHub allows you to push JavaScript and image updates to your users. **If you make breaking changes to native code, you must update your application via Apple/Google**. We recommend that you test your AppHub builds with their associated native code versions before deploying to your users. Check out the [debug builds section](http://docs.apphub.io/v1.0/docs/getting-started#section-debug-builds) for information on how to test builds with test users. --- ## Logging For debugging purposes, it can often be helpful to enable verbose logging mode: [block:code] { "codes": [ { "code": "[AppHub setLogLevel:AHLogLevelDebug];", "language": "objectivec" }, { "code": "AppHub.setLogLevel(.Debug);", "language": "swift" }, { "code": "AppHub.setLogLevel(AppHubLogLevel.Debug);", "language": "java" } ] } [/block] ## Network Usage The AppHub SDK polls for new builds of your app and downloads new builds in a background thread. By default, the AppHub SDK will only poll for new builds when the device is connected to WiFi. You can permit the SDK to download new builds on a cellular connection (WWAN) like so: [block:code] { "codes": [ { "code": "[AppHub buildManager].cellularDownloadsEnabled = YES;", "language": "objectivec" }, { "code": "AppHub.buildManager().cellularDownloadsEnabled = true", "language": "swift" }, { "code": "application.getBuildManager().setCellularDownloadsEnabled(true);", "language": "java" } ] } [/block] --- ## Listening for New Builds If you want to perform an action when a new build becomes available to your application, such as displaying an alert to the user or force refreshing the app, you can listen for new build events. You can register a listener for this event like so: [block:code] { "codes": [ { "code": "#import \"AppHub.h\"\n\n...\n \n- (instancetype)init\n{\n if ((self = [super init])) {\n [[NSNotificationCenter defaultCenter] \n addObserver:self \n selector:@selector(buildManagerDidMakeBuildAvailable:) \n name:AHBuildManagerDidMakeBuildAvailableNotification \n object:nil];\n }\n \n return self;\n}\n\n...\n \n- (void)buildManagerDidMakeBuildAvailable:(NSNotification *)notification\n{\n AHBuild *build = notification.userInfo[AHBuildManagerBuildKey];\n // Do something with the new build...\n}\n\n...\n \n- (void)dealloc\n{\n [[NSNotificationCenter defaultCenter] removeObserver:self];\n}", "language": "objectivec" }, { "code": "class AppHubModule {\n init() {\n NSNotificationCenter.defaultCenter().addObserver(self, selector: \"buildManagerDidMakeBuildAvailable:\", name: AHBuildManagerDidMakeBuildAvailableNotification, object: nil)\n }\n \n @objc private func buildManagerDidMakeBuildAvailable(notification: NSNotification){\n let build = notification.userInfo![AHBuildManagerBuildKey] as! AHBuild;\n // Do something with the build, like show an alert to the user.\n }\n \n deinit {\n NSNotificationCenter.defaultCenter().removeObserver(self)\n }\n}", "language": "swift" }, { "code": "application.getBuildManager().addNewBuildListener(new AppHubNewBuildListener() {\n\t\t@Override\n public void onNewBuild(AppHubBuild build) {\n\n }\n});", "language": "java" } ] } [/block] --- ## Debug Builds Many developers use AppHub with testing services like TestFlight and HockeyApp as it is desirable to push AppHub updates to your beta users before pushing them to production. To enable "debug" builds, enable this property in your Objective-C code and distribute to beta users: [block:code] { "codes": [ { "code": "[AppHub buildManager].debugBuildsEnabled = YES;", "language": "objectivec" }, { "code": "AppHub.buildManager().debugBuildsEnabled = true", "language": "swift" }, { "code": "application.getBuildManager().setDebugBuildsEnabled(true);", "language": "java" } ] } [/block] When deploying builds from the AppHub dashboard, configure your build to deploy to the "debug" target. [See the dashboard docs for more information](http://docs.apphub.io/docs/using-the-dashboard#section-uploading-builds). --- ## Polling for New Builds (Advanced) The AppHub SDK will poll our servers for new builds of your App. If you wish to manually control the frequency and timing of the polling, you can disable automatic polling: [block:code] { "codes": [ { "code": "[AppHub buildManager].automaticPollingEnabled = NO;", "language": "objectivec" }, { "code": "AppHub.buildManager().automaticPollingEnabled = false", "language": "swift" }, { "code": "application.getBuildManager().setAutomaticPollingEnabled(false);", "language": "java" } ] } [/block] To poll for new builds, call this method: [block:code] { "codes": [ { "code": "[[AppHub buildManager] fetchBuildWithCompletionHandler:nil];", "language": "objectivec" }, { "code": "AppHub.buildManager().fetchBuildWithCompletionHandler(nil)", "language": "swift" }, { "code": "application.getBuildManager().fetchBuild(null);", "language": "java" } ] } [/block] This method can also take a completion block as an argument: [block:code] { "codes": [ { "code": "[[AppHub buildManager] fetchBuildWithCompletionHandler: ^(AHBuild *result, NSError *error) {\n // If the `result` AHBuild is not nil, then it is guaranteed\n // to be the most up-to-date build of the app.\n}];", "language": "objectivec" }, { "code": "AppHub.buildManager().fetchBuildWithCompletionHandler {(result: AHBuild, error: NSError) -> Void in\n // If the `result` AHBuild is not nil, then it is guaranteed\n // to be the most up-to-date build of the app.\n}", "language": "swift" }, { "code": "application.getBuildManager().fetchBuild(new FetchBuildCallback() {\n\t\t@Override\n\t\tpublic void done(AppHubBuild build, AppHubException e) {\n \t\t// If the `build` is not nil, then it is guaranteed\n \t\t// to be the most up-to-date build of the app.\n\t\t}\n});", "language": "java" } ] } [/block] Some developers choose to use this method at startup to ensure that all devices have the most up-to-date build.