2013-06-18 41 views

回答

2

由於其高影響力的安全隱患,在WebSMS API目前僅適用於認證應用在Firefox OS上(請參閱WebSMS on MDN)。

經過認證的應用程序是包含在操作系統本身中的應用程序,因此 - 作爲第三方開發人員 - 目前您無法創建可使用此Web API的應用程序。但是,訪問SMS API是一項非常需要的功能,因此,長期而言,在OS中實現這一目標的工作正在進行,但不會在不久的將來。

+0

+1,感謝您的信息 – karaxuna

+0

我讀到關於它的文章,你是對的:) – karaxuna

0

是的,你可以在Firefox OS發送短信,但因爲有高影響安全的影響manifest.webapp文件使用SMS API之前,你必須編輯類型字段作爲「類型」:在許可「認證」和 字段你必須添加「短信」:{}。

之後,發送短信,您可以使用下面的代碼

var message = "hi"; //sms content 
var number = "0191147689"; //mobile no you want to send sms 
var request; 
try{ 

    request = navigator.mozMobileMessage.send(number, message); 
} 
catch(error){ 
    console.log(error.name + " occured while sending sms"); 
} 

request.onsuccess = function(){ 
    console.log("SMS has been sent"); 
} 
request.onerror = function(){ 
    console.log("Something went wrong: " + this.error); 
}