将AIR程序加上自动更新功能

AIR 1.5 加入了自动升级的类air.update.ApplicationUpdater,为基于AIR的应用程序能通过网络更新到最新版本有了保障。如果发布自己的AIR程序建议加上自动升级功能,好处当然不用多说。

其原理也很简单,ApplicationUpdater 会去读取网络上的一个版本描述文件,描述文件事是一个特定的XML文档,其中包含了版本号和对应的安装文件路径以及更新描述信息。然后和当前运行的AIR程序版本进行比较,来决定是否下载和安装。

整理了一下代码,在以后的AIR程序中只要简单的引入这个类文件即可实现检查新版本和安装新版本的AIR程序。

这里来测试,注意标题栏的版本号,升级成功后为2.0


版本描述文件

UpdateUtil.as

AutoUpdate.as

AIR 程序自动更新测试

 

有几个需要注意的不得不提醒一下。
需要Flex SDK 3.2才支持AIR 1.5

XML中的版本号和指定的AIR程序的版本号一定要保证匹配,比如1.0千万不要写成了1.00了。
如果在ADL中看到报错[ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Cannot update (from remote)" errorID=16828]
请使用发行版本来测试,调试版本不支持升级安装。

 

源码下载

 AutoUpdate.zip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个简单的AT指令程序,用于在Air724UG模块上发送短信: ```c #include <stdio.h> #include <string.h> #include <stdlib.h> #define SERIAL_PORT "/dev/ttyUSB0" // 串口设备名 #define BAUD_RATE 115200 // 波特率 // 打开串口设备 int open_serial_port(const char *device, int baud) { int fd = open(device, O_RDWR | O_NOCTTY); if (fd < 0) { perror(device); return -1; } struct termios options; tcgetattr(fd, &options); cfsetispeed(&options, baud); cfsetospeed(&options, baud); options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; tcsetattr(fd, TCSANOW, &options); return fd; } // 发送AT指令并等待响应 int send_at_command(int fd, const char *command, const char *expected_response, int timeout) { char buffer[512]; int len, i; int retries = 3; do { // 发送AT指令 write(fd, command, strlen(command)); write(fd, "\r\n", 2); // 等待响应 memset(buffer, 0, sizeof(buffer)); i = 0; do { len = read(fd, buffer + i, sizeof(buffer) - i); if (len > 0) { i += len; } } while (len > 0 && i < sizeof(buffer) - 1 && !strstr(buffer, expected_response)); // 检查响应是否符合预期 if (strstr(buffer, expected_response)) { return 0; } } while (--retries > 0); return -1; } // 发送短信 int send_sms(int fd, const char *phone_number, const char *message) { char pdu[512]; char command[512]; int i, j, len; // 将消息打包成PDU格式 len = strlen(message); sprintf(pdu, "0011000D91%s0000AA%s", phone_number, message); len = strlen(pdu) / 2; sprintf(pdu, "%02X%s", len, pdu); // 发送AT指令,设置短信中心地址 if (send_at_command(fd, "AT+CSCA=\"+8613800270500\"", "OK", 5000) != 0) { printf("Failed to set SMS center address\n"); return -1; } // 发送AT指令,设置短信发送模式为PDU模式 if (send_at_command(fd, "AT+CMGF=0", "OK", 5000) != 0) { printf("Failed to set SMS mode to PDU\n"); return -1; } // 发送AT指令,发送短信 sprintf(command, "AT+CMGS=%d", strlen(pdu) / 2); if (send_at_command(fd, command, ">", 5000) != 0) { printf("Failed to send SMS command\n"); return -1; } // 发送短信内容 write(fd, pdu, strlen(pdu)); write(fd, "\x1A", 1); // 等待短信发送完成 for (i = 0; i < 10; i++) { memset(command, 0, sizeof(command)); sprintf(command, "AT+CMGS=%d", strlen(pdu) / 2); write(fd, command, strlen(command)); write(fd, "\r\n", 2); j = 0; do { len = read(fd, command + j, sizeof(command) - j - 1); if (len > 0) { j += len; } } while (len > 0 && j < sizeof(command) - 1 && !strstr(command, "+CMGS:")); if (strstr(command, "+CMGS:")) { printf("SMS sent successfully\n"); return 0; } sleep(1); } printf("Failed to send SMS\n"); return -1; } int main() { int fd = open_serial_port(SERIAL_PORT, BAUD_RATE); if (fd < 0) { return -1; } // 在此处填写您的手机号码和短信内容 const char *phone_number = "13800138000"; const char *message = "Hello, World!"; send_sms(fd, phone_number, message); close(fd); return 0; } ``` 此程序实现了在Air724UG模块上发送短信的基本功能。您需要根据您的具体需求修改和扩展此程序。同时请注意,发送短信需要正确配置模块的通信参数和短信中心地址等信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值