LoginSignup
0
0

More than 5 years have passed since last update.

PhoneGap BuildでBackground Fetch

Last updated at Posted at 2015-11-03

iOSのBackground Fetch

今更ですが、iOSでバックグラウンドで何らかのジョブを行う場合、Background Fetchを利用することになる。

Background Fetch を試してみた
http://qiita.com/griffin_stewie/items/8371c09059b3ba7bb202

cordovaにもそれに対応したプラグインがあり、
PhoneGap Build https://build.phonegap.com/ で利用可能な様子。

CDVBackgroundFetch - Cordova Background Fetch Plugin
https://build.phonegap.com/plugins/955

サンプルソースコード

Parse.comにデータを登録するサンプルソースコード。
ただし、Background Fetchの仕様は特に呼出間隔が決められていない。30分単位とかそれ以上でしかデータが増えていかない気がする。

config.xml
<gap:plugin name="org.transistorsoft.cordova.plugin.background.fetch" />    
// AngularJSベース
angular.module('myApp', [])
.factory('shared',['$http',function($http){
  var _o = {
    appId : "[parse.comのアプリケーションID]",
    apiKey : "[parse.comのAPI KEY]",

    // BackgroundFetchを利用し、Parse.comにデータを登録する       
    sampleFetchPostParse: function() {
      var Fetcher = window.plugins.backgroundFetch;

      var fetchCallback = function() {
        // parse.com の APIを呼び出す
        $http({
          'method':'POST',
          'url':'https://api.parse.com/1/classes/SampleData',
          'headers':{
            "X-Parse-Application-Id": _o.appId,
            "X-Parse-REST-API-Key": _o.apiKey,
          },
          'data':{
            "name": "sample name",
          }
        })
        .then(function(){
          // ネイティヴ側スレッドを停止する
          Fetcher.finish();                     
        });
      }
      // Fetchを設定する
      Fetcher.configure(fetchCallback);
    }
  };
  return _o;
}])
;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0