我想尝试将Volley与OkHttp结合使用,但是Volley缓存系统和OkHttp都依赖于HTTP规范中定义的HTTP缓存.那么如何禁用OkHttp的缓存以保留一份HTTP缓存?
编辑:我做了什么
public class VolleyUtil {
// http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/
private volatile static RequestQueue sRequestQueue;
/** get the single instance of RequestQueue **/
public static RequestQueue getQueue(Context context) {
if (sRequestQueue == null) {
synchronized (VolleyUtil.class) {
if (sRequestQueue == null) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
client.setCache(null);
sRequestQueue = Volley.newRequestQueue(context.getApplicationContext(), new OkHttpStack(client));
VolleyLog.DEBUG = true;
}
}
}
return sRequestQueue;
}
}
Run Code Online (Sandbox Code Playgroud)
这OkHttpClient是从引用https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750
我需要根据id使用PHPQuery的下拉列表获取数组中下拉列表的所有值.
以下是HTML:
<select name="semester" id="semester" class="inputtxt" onChange="javascript:selectSemester(this, this.form);">
<option value="">-- Select your Semester --</option>
<option value="2nd" selected>2nd</option>
<option value="4th" >4th</option>
<option value="6th" >6th</option>
<option value="8th" >8th</option>
<option value="SE1" >SE1</option>
<option value="SE3" >SE3</option>
<option value="SE5" >SE5</option>
<option value="SE7" >SE7</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
$semesters = $all['#semester'];
foreach ($semesters as $semester) {
echo pq($semester)->text();
echo '<br>';
}
Run Code Online (Sandbox Code Playgroud)
但是我只得到一个输出,并且所有值都连接在一起.如何将每个值作为数组中的单独元素?
我需要使用PHP将所有字符串和数字用双引号放在CSV文件中.
如何在双引号内的所有数据中从PHP创建CSV文件?
我正在使用此代码生成CSV - 我正在使用codeigniter框架
$array = array(
array(
(string)'XXX XX XX',
(string)'3',
(string)'68878353',
(string)'',
(string)'xxxx@xxxx.xxx.xx',
),
);
$this->load->helper('csv');
array_to_csv($array, 'blueform.csv');
Run Code Online (Sandbox Code Playgroud)
输出我得到:
"XXX XX XX",3,68878353,,xxxx@xxxx.xxx.xx
Run Code Online (Sandbox Code Playgroud)
预期产出:
"XXX XX XX","3","68878353","","xxxx@xxxx.xxx.xx"
Run Code Online (Sandbox Code Playgroud)
array_to_csv的代码
if (!function_exists('array_to_csv')) {
function array_to_csv($array, $download = "") {
if ($download != "") {
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $download . '"');
}
ob_start();
$f = fopen('php://output', 'w') or show_error("Can't open php://output");
$n = 0;
foreach ($array as $line) {
$n++;
if (!fputcsv($f, $line)) {
show_error("Can't write line $n: …Run Code Online (Sandbox Code Playgroud) 我在spinnerRanger.setSelection之后编写Spinner的事件setOnItemSelectedListener.
我认为Toast.makeText(...)第一次运行APP时不会启动,但仍会显示提示信息,为什么?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.cleanup_delete_fragment_old, container, false);
mView = rootView;
mContext = rootView.getContext();
InitValueOfControls();
return rootView;
}
private void InitValueOfControls() {
spinnerRanger = (Spinner)mView.findViewById(R.id.spinner);
PublicParFun.FillRangeSpinner(mView, spinnerRanger);
spinnerRanger.setSelection(PublicParFun.GetIndexOfRangeDeleteOld(mContext));
spinnerRanger.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(mContext, "My "+position, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
致Trevor Carothers:
如果我DoLongTimeOperation()在Selection侦听器事件之前插入一个 ,它还会显示toast吗?
private void InitValueOfControls() …Run Code Online (Sandbox Code Playgroud) 我已将Urban Airship SDK集成到Android 4.2(Jelly Bean)设备上的应用程序中.我收到了一般的推送通知.没关系.但我希望通过带有"保存"标签的按钮获得交互式推送通知.
我的依赖来自build.gradle:
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile project (':urbanairship-lib-6.1.1')
compile 'com.android.support:support-v4:22.2.0'
// Recommended for in-app messaging
compile 'com.android.support:cardview-v7:22.2.0'
// Recommended for location services
compile 'com.google.android.gms:play-services-location:7.5.0'
// Required for Android (GCM) push notifications
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile files('libs/commons-io-2.4.jar')
compile files('libs/FlurryAnalytics-4.1.0.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}
Run Code Online (Sandbox Code Playgroud)
根据官方文档,我onCreate()在MyApplication类中的方法中添加了以下代码:
@Override
public void onCreate() {
AirshipConfigOptions options = new AirshipConfigOptions();
options.developmentAppKey = "sdgsdgsdhsdh";
options.developmentAppSecret = "sdhsdhsdhsdhsh";
options.productionAppKey = "Your Production App Key"; …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题,我似乎无法找到解决方案或更接近我遇到的问题,
这是事情,我有一个通过php在命令行上运行的scoket脚本,它接受连接并从移动应用程序客户端读取json格式的数据,并在json中发送适当的响应.
一切正常,但连接数不超过256连接.
我想知道为什么会这样,我该如何解决呢?我已经这么多天了,但没有运气!
这是脚本片段
<?php
date_default_timezone_set("UTC");
$server = stream_socket_server("tcp://192.168.1.77:25003", $errno, $errorMessage);
if (!$server) {
die("$errstr ($errno)");
}
echo "Server started..";
echo "\r\n";
$client_socks = array();
while (true) {
//prepare readable sockets
$read_socks = $client_socks;
$read_socks[] = $server;
//start reading and use a large timeout
if (!stream_select ($read_socks, $write, $except, 10000)) {
die('something went wrong while selecting');
}
//new client
if (in_array($server, $read_socks)) {
$new_client = stream_socket_accept($server);
if ($new_client) {
//print remote client information, ip and port number
echo 'Connection …Run Code Online (Sandbox Code Playgroud) 免责声明:在SO上我发现了许多类似的问题和一些答案,但没有一个解决了我的问题.
我有这个简单的PHP代码:
<?php
$deviceToken = "myDeviceToken";
$message = "Hello from server";
$badge = 1;
$sound = "default";
// Construct the notification payload
$body['aps'] = array(
'alert' => $message
);
if ($badge) {
$body['aps']['badge'] = $badge;
}
if ($sound) {
$body['aps']['sound'] = $sound;
}
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'my.pem');
$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
} else {
print …Run Code Online (Sandbox Code Playgroud) 在这里,我使用ckeditor插入记录并使用ckeditor上传图像.当我要在添加时插入图像时,我可以使用kcfinder上传图像.那时我正在获取插入图像的链接,(当我得到链接时http://localhost/project/ABC/policies/add)
http://localhost/svn_project/PMS/resource/kcfinder/browse.php?opener=ckeditor&type=images&CKEditor=description&CKEditorFuncNum=1&langCode=en
Run Code Online (Sandbox Code Playgroud)
但是,当我想要编辑该记录以上传图像时,它会显示这样的符号,(当我得到链接时http://localhost/project/ABC/policies/edit/2)
http://localhost/svn_project/PMS/hr_policies/resource/kcfinder/browse.php?opener=ckeditor&type=images&CKEditor=description&CKEditorFuncNum=1&langCode=en
Run Code Online (Sandbox Code Playgroud)
在ckeditor的config.js中,
CKEDITOR.editorConfig = function(config) {
// Define changes to default configuration here.
// For complete reference see:
// http://docs.ckeditor.com/#!/api/CKEDITOR.config
config.filebrowserBrowseUrl = '../resource/kcfinder/browse.php?opener=ckeditor&type=files';
config.filebrowserImageBrowseUrl = '../resource/kcfinder/browse.php?opener=ckeditor&type=images';
config.filebrowserFlashBrowseUrl = '../resource/kcfinder/browse.php?opener=ckeditor&type=flash';
config.filebrowserUploadUrl = '../resource/kcfinder/upload.php?opener=ckeditor&type=files';
config.filebrowserImageUploadUrl = '../resource/kcfinder/upload.php?opener=ckeditor&type=images';
config.filebrowserFlashUploadUrl = '../resource/kcfinder/upload.php?opener=ckeditor&type=flash';
config.removeDialogTabs = 'link:advanced';
};
Run Code Online (Sandbox Code Playgroud)
那么,在编辑时我应该怎么做,我可以上传图像.
我们的推送通知脚本已经工作了近一年,但突然停止了工作.该脚本执行以下操作:
查询DB以获取iPhone设备令牌列表
打开与Apple的实时APNS服务器的SSL套接字连接
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client($apnsHost, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
Run Code Online (Sandbox Code Playgroud)创建一个255字节大小的消息的有效负载
$payload = '{
"aps": {
"alert": "' . $message . '",
"badge": 1,
"sound": "default"
}
}';
Run Code Online (Sandbox Code Playgroud)循环遍历每个设备并将有效负载写入打开的连接.
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
fwrite($fp, $msg);
Run Code Online (Sandbox Code Playgroud)然后关闭连接.
fclose($fp);
Run Code Online (Sandbox Code Playgroud)所以我的问题是 - 脚本中的任何内容都没有改变,但HAS改变的是数据库的大小.我创建了一个Web界面,允许用户将有效负载发送到所有iphone设备,运行时只需几秒钟即可发送/加载.虽然数据库中的设备数量(大约3500)可能会产生问题吗?
当我写入套接字时,我可以发送推送通知的最大设备数是多少?是否存在最大值或限制?
我有文本文件包含CSV文件格式的样本,我希望我的用户可以在链接点击下载该文件.
此文件位于此文件夹结构中:
资产 - > csv->采样CSV-Format.txt
这是我尝试过的代码:
<?php
$file_name = "Sample-CSV-Format.txt";
// extracting the extension:
$ext = substr($file_name, strpos($file_name,'.') + 1);
header('Content-disposition: attachment; filename=' . $file_name);
if (strtolower($ext) == "txt") {
// works for txt only
header('Content-type: text/plain');
} else {
// works for all
header('Content-type: application/' . $ext);extensions except txt
}
readfile($decrypted_file_path);
?>
<p class="text-center">Download the Sample file <a href="<?php echo base_url();?>assets/csv/Sample-CSV-Format.txt">HERE</a> It has a sample of one entry</p>
Run Code Online (Sandbox Code Playgroud)
此代码在页面加载时下载文件而不是链接单击.此外,它正在下载页面的整个html结构我只想要文本文件中我写的文本.
请指导问题在哪里?
要将我的服务器与APN服务器连接,请使用以下代码.
// coonecting the apn server
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $errorNo, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
Run Code Online (Sandbox Code Playgroud)
但我无法连接,我打印$ errorNo和$ errorString输出是:错误:连接超时errorNo:110
但我也在errorLog中收到以下警告:
无法连接到第35行/home/riseupla/public_html/applications/apn/apn.php中的ssl://gateway.sandbox.push.apple.com:2195(连接超时)
我该怎么办?
注意:我可以通过我的mac项目发送推送通知(使用push me baby项目).但我的PHP项目无法连接.
我是 iOS 开发的新手,我想知道如何制作像这样的“保持按钮”来录制我的音频?是否可以?