Cordova 从JS识别Phonegap移动应用程序
我们正在构建一个web应用程序,它为用户创建自己的移动应用程序并在其个人资料中管理其内容提供了能力。移动应用程序对我们所有的用户都有相似的功能,唯一不同的是它的内容。因此,当一个人来在我们的网络服务中创建一个移动应用程序,然后他添加一些新闻、照片等-他的移动应用程序应该只显示他的新闻和照片,另一个人将拥有他自己的移动应用程序,其中包含他自己的新闻和照片 要获取特定应用程序的内容,我们有唯一的API密钥,使用此API密钥移动应用程序将向我们的API发出请求以获取唯一的内容 但主要的问题是,我们不知道如何在移动应用程序中嵌入这个API密钥 情况如下:Cordova 从JS识别Phonegap移动应用程序,cordova,phonegap-plugins,phonegap-build,Cordova,Phonegap Plugins,Phonegap Build,我们正在构建一个web应用程序,它为用户创建自己的移动应用程序并在其个人资料中管理其内容提供了能力。移动应用程序对我们所有的用户都有相似的功能,唯一不同的是它的内容。因此,当一个人来在我们的网络服务中创建一个移动应用程序,然后他添加一些新闻、照片等-他的移动应用程序应该只显示他的新闻和照片,另一个人将拥有他自己的移动应用程序,其中包含他自己的新闻和照片 要获取特定应用程序的内容,我们有唯一的API密钥,使用此API密钥移动应用程序将向我们的API发出请求以获取唯一的内容 但主要的问题是,我们不知
- 我们使用Phonegap创建移动应用程序,原始代码是HTML+JS。为了构建应用程序,我们使用Phonegap构建API,这需要一个JS应用程序从Github存储库交付或作为ZIP存档。因为唯一不同的是内容(每个用户应用程序的HTML+JS代码库都是相同的),所以我们决定对所有用户应用程序使用单一的Github存储库。而且,维护一个存储库比维护多个存储库更容易
- 我们使用Phonegap构建API为用户自动创建移动应用程序。因此,当用户按下“创建”键时,Phonegap移动应用程序将使用Github存储库代码创建。Phonegap构建API“create”方法允许设置应用程序的标题、描述、版本、包等。因此,每个应用程序都有一些自定义设置。此设置在应用程序生成之前和之后都是可配置的,因此我们可以更改标题、版本或包
谢谢。如果您在构建之前修改config.xml文件(包括包名和标题),您可以在那里放置一个apiKey,然后使用jQuery使用此方法读取
$.get("config.xml", function(data){
alert($(data).find('widget').attr('apiKey'));
});
<widget id="com.example.hello" version="1.0.0" apiKey="API_KEY_HERE">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
</widget>
$.get(“config.xml”,函数(数据){
警报($(数据).find('widget').attr('apiKey'));
});
你好世界
响应deviceready事件的Apache Cordova应用程序示例。
如果在生成之前修改config.xml文件(包括包名和标题),可以在其中放置一个apiKey,然后使用jQuery使用此方法读取
$.get("config.xml", function(data){
alert($(data).find('widget').attr('apiKey'));
});
<widget id="com.example.hello" version="1.0.0" apiKey="API_KEY_HERE">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
</widget>
$.get(“config.xml”,函数(数据){
警报($(数据).find('widget').attr('apiKey'));
});
你好世界
响应deviceready事件的Apache Cordova应用程序示例。
如果在生成之前修改config.xml文件(包括包名和标题),可以在其中放置一个apiKey,然后使用jQuery使用此方法读取
$.get("config.xml", function(data){
alert($(data).find('widget').attr('apiKey'));
});
<widget id="com.example.hello" version="1.0.0" apiKey="API_KEY_HERE">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
</widget>
$.get(“config.xml”,函数(数据){
警报($(数据).find('widget').attr('apiKey'));
});
你好世界
响应deviceready事件的Apache Cordova应用程序示例。
如果在生成之前修改config.xml文件(包括包名和标题),可以在其中放置一个apiKey,然后使用jQuery使用此方法读取
$.get("config.xml", function(data){
alert($(data).find('widget').attr('apiKey'));
});
<widget id="com.example.hello" version="1.0.0" apiKey="API_KEY_HERE">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
</widget>
$.get(“config.xml”,函数(数据){
警报($(数据).find('widget').attr('apiKey'));
});
你好世界
响应deviceready事件的Apache Cordova应用程序示例。
我建议您将所有特定于客户端的配置选项保存在单独的JS文件中,我们将其命名为client.JS。
该文件将作为构建过程的一部分生成,您可以将其与移动应用程序的其他源代码一起放入ZIP文件中
client.js
var clientSettings = {
apiId: "API-ID",
apiSecret: "Your Secret",
}
client.js使用情况
if (clientSettings !== undefined) {
// Your mobile specific code goes here, take API keys, version, platform etc.
// what ether you put in client.js could be accessed from here
} else {
// We are running from the browser. Go different path and use other API
}
作为预防措施,我建议将client.js添加到.gitignore中。我建议您将所有特定于客户端的配置选项保留在单独的js文件中,我们将其命名为client.js。 该文件将作为构建过程的一部分生成,您可以将其与移动应用程序的其他源代码一起放入ZIP文件中 client.js
var clientSettings = {
apiId: "API-ID",
apiSecret: "Your Secret",
}
client.js使用情况
if (clientSettings !== undefined) {
// Your mobile specific code goes here, take API keys, version, platform etc.
// what ether you put in client.js could be accessed from here
} else {
// We are running from the browser. Go different path and use other API
}
作为预防措施,我建议将client.js添加到.gitignore中。我建议您将所有特定于客户端的配置选项保留在单独的js文件中,我们将其命名为client.js。 该文件将作为构建过程的一部分生成,您可以将其与移动应用程序的其他源代码一起放入ZIP文件中 client.js
var clientSettings = {
apiId: "API-ID",
apiSecret: "Your Secret",
}
client.js使用情况
if (clientSettings !== undefined) {
// Your mobile specific code goes here, take API keys, version, platform etc.
// what ether you put in client.js could be accessed from here
} else {
// We are running from the browser. Go different path and use other API
}
作为预防措施,我建议将client.js添加到.gitignore中。我建议您将所有特定于客户端的配置选项保留在单独的js文件中,我们将其命名为client.js。 这个fi