ITeye博客

[源代码]一个有用的链接管理器

haiker · 2011-02-23 11:25 · webOS · 移动开发 · Palm · Markdown

var ConnectMgr = Class.create({
    initialize:function() {
        this.connected = 0;
        this._checkConnection();
    },

    _checkConnection : function() {
        try {
            var controller = Mojo.Controller.stageController.activeScene();
            controller.serviceRequest('palm://com.palm.connectionmanager/',
              {
                  method: 'getstatus',
                  parameters:
                    {
                        subscribe: true
                    },
                  onSuccess: this._checkSuccess.bind(this),
                  onFailure: this._checkFailure.bind(this)
              });
        }
        catch (e) {
            Mojo.Log.error('ConnectMgr -', e);
        }
    },

    _checkSuccess:function(response) {
        Mojo.Log.info('ConnectMgr - _checkSuccess', response.isInternetConnectionAvailable);
        this.connected = response.isInternetConnectionAvailable;
    },

    _checkFailure:function(response) {
        Mojo.Log.error('ConnectMgr - Connection Check Error:', response.errorText, '(Code', response.code, ')');
    }
});

 

 使用方式:

activate : function(event) {
    // Check connection status
    connmgr = new ConnectMgr();
}

 

if (!connmgr.connected) {
    Mojo.Controller.errorDialog('Request cannot be processed without a network connection.');
    return;
} 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。