我的应用程序包中有一些嵌入式html.我正在使用loadHtmlString来加载它.同时我的文档文件夹中有一些图像文件.我想用html中的img替换我的文档文件夹中的文件.例如,这是我有的示例html:
<div id="image">
<a href="image">
<img src="@image" class="center">
</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码将@image替换为文档中的文件路径:
NSString* imgFile = [NSString stringWithFormat:@"file:///%@/%@",
[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images"],@"myimage.png"];
text = [text stringByReplacingOccurrencesOfString:@"@image" withString:imgFile];
NSURL* baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];
[self.webView loadHTMLString:text baseURL:baseUrl];
Run Code Online (Sandbox Code Playgroud)
(text是我的html文件的html文本).
它在第一次调用此代码时有效.但是,例如,如果我修改myimage.png并再次调用代码,我仍然会显示修改前的图像.(我已经在我的文档文件夹中检查了我的文件,它已经被正确修改了).
我怀疑它是由缓存引起的.有人可以提供建议吗?
谢谢
注意:
它是由缓存引起的.我通过使用以下方法强制UIWebView加载图像的新副本来解决问题:
NSString* imgFile = [NSString stringWithFormat:@"file:///%@/%@?t=%d",
[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images"],@"myimage.png",time(NULL)];
text = [text stringByReplacingOccurrencesOfString:@"@image" withString:imgFile];
Run Code Online (Sandbox Code Playgroud) 请看下面的代码:
$msgs = Message::where(function($query) use ($start,$end){
$query->whereBetween('created_at', array($start, $end));
})->orderBy('created_at', 'DESC');
$first = $msgs->first()->created_at;
$ids = $msgs->lists('id');
Run Code Online (Sandbox Code Playgroud)
我想要做的是获取查询结果集的最新日期,并同时从结果中获取所有ID.但代码不起作用,因为$ msgs由$ msgs-> first()函数更改.我想知道是否有办法让我获得查询结果的第一个元素而不影响整个结果集?谢谢
有一些与此问题相关的问题.例如,这一个.但它不起作用.
让我展示一下我在代码中所做的事情.
activity_main.xml中
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame" >
<fragment
android:id="@+id/my_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.zhouhao.test.MyFragment"
tools:layout="@layout/fragment_my" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
fragment_my.xml(我的主要片段包含FragmentTabHost)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:orientation="horizontal">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="95"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/panel_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
Run Code Online (Sandbox Code Playgroud)
fragment_tab1.xml(对于与不同选项卡对应的片段,它们类似,所以我只显示一个代码)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.zhouhao.test.TabFragment">
<!-- TODO: Update blank fragment layout -->
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:text="@string/fragment_tab1" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
protected …Run Code Online (Sandbox Code Playgroud) 我在Google Analytics帐户中的配置:

我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
GAI *gai = [GAI sharedInstance];
//gai.optOut = YES;
gai.trackUncaughtExceptions = YES; // report uncaught exceptions
gai.logger.logLevel = kGAILogLevelVerbose; // remove before app release
[[GAI sharedInstance] setDispatchInterval:10.0];
[[GAI sharedInstance] trackerWithTrackingId:@"UA-xxxxxx-3"];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在视图控制器中:
(void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Detail Screen"];
[[GAI sharedInstance].defaultTracker send:[[GAIDictionaryBuilder createScreenView] build]];
Run Code Online (Sandbox Code Playgroud)
}
它确实在我的控制台中显示:
2015-06-24 15:03:36.592 GoogleAnalyticsDemoiOS[9540:264576] VERBOSE: GoogleAnalytics 3.12 +[GAITrackerModel initialize] (GAITrackerModel.m:88): idfa class missing, won't collect idfa
2015-06-24 15:03:36.619 GoogleAnalyticsDemoiOS[9540:264576] …Run Code Online (Sandbox Code Playgroud) 关于蓝牙低功耗.我知道iOS 4及以上的iPhone 4S,iPhone 5,iPad 3支持BLE 4.0.我从Apple那里阅读了示例代码TemperatureSensor.我的问题是传感器的要求是什么?换句话说,在这个应用中可以连接什么样的传感器?是否所有支持BLE 4.0的设备都可以在支持BLE 4.0的iOS设备上连接?
我的代码突然无法在Xcode 6.1中编译(我确信它在Xcode 6 GM和beta版本中工作).它显示错误消息:
'NSInvocationOperation'不可用
我的代码是:
let operation = NSInvocationOperation(target:self, selector:"backgroundRun:", object:self)
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?谢谢.
我正在尝试使用SharedPreferencesBackupHelper将我的SharedPreferences值保存到云中。
AndroidManifest.xml
<application
android:allowBackup="true"
android:backupAgent=".DataBackupAgent"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.backup.api_key" android:value="AEdPqrEAAAAIXMH86OqosQlXYuS0QbfyOaZT8fUadY1QUDzo2w" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
DataBackupAgent.java:
公共类DataBackupAgent扩展了BackupAgentHelper {
public static final String PREFS = "data_prefs";
public static final String PREFS_BACKUP_KEY = "myprefs";
@Override
public void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
}
Run Code Online (Sandbox Code Playgroud)
}
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
backupManager = new BackupManager(this);
prefs = getSharedPreferences(DataBackupAgent.PREFS, Context.MODE_PRIVATE);
edit = prefs.edit();
text …Run Code Online (Sandbox Code Playgroud) 我正在使用S3TransferManager-Sample进行测试.我创建了Cognito并设置了IAM并最后更改了constants.swift文件.我没有上传但无法下载的问题.错误消息是:
下载失败:[错误域= com.amazonaws.AWSS3ErrorDomain代码= 1"操作无法完成.(com.amazonaws.AWSS3ErrorDomain错误1.)"UserInfo = 0x7f8cd658a5a0 {HostId = d4yLouhlYmGn4s1Zp54 + EOsZQEy2bVEGNs5XIa8pMxerJggANV/9Zb82c1QtF/5Hsn5KqYXGqdw =,消息=拒绝访问,代码= AccessDenied,RequestId = A1966393EAC3F15F}]
以下是我对该角色的设置:


我在S3存储桶中的设置:

当然,当我添加"Everyone"以允许"List"权限时,我可以下载.但是Cognito的目的是什么呢?谢谢
我想知道是否可以在角度2的以下用例中使用可观察或承诺:
有两个异步上传任务.我想知道如何检测这两项任务都已完成.
我的上传任务(在promise中实现,但如果需要可以很容易地更改为observable)是这样的:
myService.upload('upload1').then(() => {
})
myService.upload('upload2').then(() => {
})
Run Code Online (Sandbox Code Playgroud)
如何将这两个事件链接在promise或者observable中,以便我知道这两个任务都已完成了?谢谢
我正在尝试使用ionic.io发送推送通知.这是我做的:
ionic.io仪表板中创建api令牌我在app.js中的源代码是由ionic start pushdemo生成的
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
alert(token.token);
console.log("Device token:",token.token);
push.saveToken(token);
});
Run Code Online (Sandbox Code Playgroud)7.添加推送插件:
离子插件添加phonegap-plugin-push --variable SENDER_ID ="myproject_number"
我在myproject_number周围尝试了或不带引号.这是第1步中的项目编号.
8.将dev_push设置为false
9.通过离子io init将我的应用程序挂钩到ionic.io
10.Run 离子运行android -lc
找到以下错误消息:
它出什么问题了?有人可以帮忙吗?谢谢.