我正在使用 appcelerator Titan 创建一个移动(iphone/android)应用程序。有什么方法可以让应用程序使用 appcelerator 钛向任何给定号码发送短信?
7 回答
有一个功能可以用来发送短信:
var SMS_SENT = -1,
SMS_NOT_SENT = 0;
/**
* Open an SMS dialog with the given message.
* If the SMS is sent, run the onSuccess callback.
*
* @message {text} the text you want to send
* @callback {function} the funciton you want to run on success
**/
function openSmsDialog(message, onSuccess) {
if (Ti.Platform.osname === 'android') {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: 'vnd.android-dir/mms-sms'
});
intent.putExtra('sms_body', message);
var _onClose = function(activityResult) {
if (activityResult.resultCode === SMS_SENT && onSuccess) {
onSuccess();
}
};
Ti.Android.currentActivity.startActivityForResult(intent, _onClose);
} else {
var smsModule = require("com.omorandi");
var smsDialog = smsModule.createSMSDialog({
messageBody: message
});
if (onSuccess) {
smsDialog.addEventListener('complete', onSuccess);
}
}
}
要使此代码在 iOS 上运行,您必须使用com.omorandi模块。对于 android,您不需要任何模块。
如果您不想付款,这里有一个适用于 iOS 的 SMS 模块:
http://developer.appcelerator.com/question/97961/ios-sms-dialog-module
你需要遵循他的指南,但你应该能够让它发挥作用。对于 android,您可以简单地调用带有“sms://”+phoneNumber 或类似名称的 URL。
这里有一些 Titanium 模块:https ://marketplace.appcelerator.com/listing?1201386205&q=sms
刚刚在谷歌搜索其他东西时发现了你的问题。所以我想我会回答,以防将来有人遇到这个Q。
Appcelerator Marketplace 中有一个用于发送 SMS 消息的模块:https ://marketplace.appcelerator.com/apps/6521?1019589994
Appcelerator 有一组模块,如果您是其中一个合作伙伴计划的成员,您可以使用这些模块。它包括一个短信模块:
如果您只想使用您自己的信息打开 SMS 应用程序,您可以使用以下内容:
Ti.Platform.openURL("sms:01234567891&body=hey");
请注意,数字和正文都是可选的。