diff --git a/client/package.json b/client/package.json
index b1addc3f9..a0c314e8b 100644
--- a/client/package.json
+++ b/client/package.json
@@ -75,7 +75,8 @@
{
"locator": "https://github.com/WizardFactory/cordova-plugin-todayweather-config.git",
"id": "cordova-plugin-todayweather-config"
- }
+ },
+ "cordova-plugin-apple-watch"
],
"cordovaPlatforms": [
{
diff --git a/client/www/index.html b/client/www/index.html
index 885be3206..60e79ce73 100644
--- a/client/www/index.html
+++ b/client/www/index.html
@@ -34,6 +34,7 @@
+
diff --git a/client/www/js/app.js b/client/www/js/app.js
index 07667368c..bbc9676fd 100644
--- a/client/www/js/app.js
+++ b/client/www/js/app.js
@@ -21,6 +21,7 @@ angular.module('starter', [
'controller.settingctrl',
'controller.guidectrl',
'controller.purchase',
+ 'controller.watch',
'controller.units',
'controller.start',
'service.run'
diff --git a/client/www/js/controller.watch.js b/client/www/js/controller.watch.js
new file mode 100644
index 000000000..4609ddb3d
--- /dev/null
+++ b/client/www/js/controller.watch.js
@@ -0,0 +1,39 @@
+/**
+ * Created by aleckim on 2017. 10. 24..
+ * https://github.com/DVenkatesh/cordova-plugin-watchconnectivity
+ */
+
+angular.module('controller.watch', []).factory('Watch', function () {
+ var obj = {};
+ obj.appGroupId;
+
+ obj.sendUserDefaults = function (obj, callback) {
+ if (!this.appGroupId) {
+ return callback(new Error("App group id is null"));
+ }
+
+ applewatch.sendUserDefaults(function () {
+ callback();
+ },
+ function () {
+ callback(new Error("Fail to send user defaults"));
+ },
+ obj, this.appGroupId);
+ };
+
+ obj.init = function (appGroupId) {
+ var that = this;
+ if(window.applewatch == undefined) {
+ console.log("Fail to load applewatch");
+ return;
+ }
+ applewatch.init(function (id) {
+ that.appGroupId = id;
+ console.log('applewatch is initialized group id='+id);
+ }, function () {
+ console.log('applewatch fail to init');
+ }, appGroupId);
+ };
+
+ return obj;
+});
diff --git a/client/www/js/service.run.js b/client/www/js/service.run.js
index 63014d341..21f0a59e0 100644
--- a/client/www/js/service.run.js
+++ b/client/www/js/service.run.js
@@ -1,5 +1,5 @@
angular.module('service.run', [])
- .run(function($rootScope, $ionicPlatform, WeatherInfo, Util) {
+ .run(function($rootScope, $ionicPlatform, WeatherInfo, Util, Watch) {
//위치 재조정해야 함.
if (twClientConfig.debug) {
Util.ga.debugMode();
@@ -102,6 +102,10 @@ angular.module('service.run', [])
Util.ga.trackEvent('app', 'status', 'pause');
}, false);
+ if (ionic.Platform.isIOS()) {
+ Watch.init(Util.suiteName);
+ }
+
WeatherInfo.loadCities();
WeatherInfo.loadTowns();
$ionicPlatform.on('resume', function(){
diff --git a/client/www/js/service.weatherinfo.js b/client/www/js/service.weatherinfo.js
index 6c0e590ea..00ef83e3a 100644
--- a/client/www/js/service.weatherinfo.js
+++ b/client/www/js/service.weatherinfo.js
@@ -1,5 +1,5 @@
angular.module('service.weatherinfo', [])
- .factory('WeatherInfo', function ($rootScope, WeatherUtil, Util) {
+ .factory('WeatherInfo', function ($rootScope, WeatherUtil, Util, Watch) {
var cities = [];
var cityIndex = -1;
var obj = {
@@ -295,6 +295,14 @@ angular.module('service.weatherinfo', [])
Util.ga.trackEvent('plugin', 'error', 'saveAppPreferences');
Util.ga.trackException(error, false);
}, 'cityList', JSON.stringify(pList));
+
+ if (ionic.Platform.isIOS()) {
+ Watch.sendUserDefaults(pList, function (err) {
+ if (err) {
+ Util.ga.trackEvent('watch', 'error', 'sendUserDefaults');
+ }
+ });
+ }
};
obj._loadCitiesPreference = function (callback) {