问题的简短版本
是否可以启动ACTION_SEND意图以共享光盘上的文件,但共享使用的文件名不同于光盘上的文件名?
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("somepath/3c72ae1adacb.dat"));
// BEGIN Hopefully something like this exists....
shareIntent.putExtra(Intent.EXTRA_FILENAME, "CuteKittens.png"));
// END
startActivity(shareIntent);
Run Code Online (Sandbox Code Playgroud)
长版......
出于安全考虑,我的Android应用程序中使用的某些文件掩盖了光盘上的文件名,例如"3c72ae1adacb.dat".
我希望登录的用户能够共享这些文件,但文件名不明确,如"CuteKittens.png".
这可以实现吗?(理想情况下,不要在光盘上复制文件,共享副本并最终删除它,这对于如此直接的事情似乎很多工作).
得到了一个.NET/C#问题......
我需要解析一些"multipart/form-data"格式的输入发布数据,以提取传递的用户名和密码.任何人都知道如何在不编写自己的解析代码的情况下执行此操作
请注意输入的帖子数据如下所示:
---------1075d313df8d4e1d
Content-Disposition: form-data; name="username"
x@y.com
---------1075d313df8d4e1d
Content-Disposition: form-data; name="password"
somepassword
---------1075d313df8d4e1d--
Run Code Online (Sandbox Code Playgroud)
为了展示我的代码,目前看起来像这样:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Login", BodyStyle = WebMessageBodyStyle.Bare)]
public Stream Login(Stream input)
{
string username = String.Empty;
string password = String.Empty;
StreamReader sr = new StreamReader(input);
string strInput = sr.ReadToEnd();
sr.Dispose();
// Help needed here:
usermame = ?.Parse(strINput, "username");
password = ?.Parse(strINput, "password");
// blah blah blah return login XML response as a Stream
}
Run Code Online (Sandbox Code Playgroud) 我是一个真正的泡菜,迫切需要一些关于我遇到的关键问题的帮助.
我花了几个月的时间编写一个HTML5应用程序/网站以及一个原生的Android应用程序,它只是HTML5网站的WebView包装器.该应用程序的核心功能之一是用户可以将应用程序特定的URL共享到Facebook和Twitter等,以便他们的朋友可以关注共享URL,这将在我们的浏览器中打开我的应用程序的HTML5版本,或者如果它们是最重要的在Android上,他们已经安装了我的原生Android应用程序,他们被提议在我的应用程序中打开.
这是一个相当长的复杂问题,所以为了简化,我会在这篇文章中一致地使用某些特定术语:
我的AndroidManifest.xml包含以下内容......
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="myapp.com" android:pathPrefix="/" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
在任何正常情况下测试时,这都可以完美运行.例如,如果"MyApp用户"跟随到http://myapp.com/sharedpage的直接链接,则会出现"选择应用程序对话框".太棒了,我确实正确配置了我的AndroidManifest.xml.
然而事情并不总是在关键的Facebook共享场景中工作.它并不总是有效,因为Facebook的原生Android应用程序和Facebook的移动网站(http://m.facebook.com)都没有直接链接到共享URL,而是通过Facebook重定向页面链接.例如,如果共享http://myapp.com/sharedpage,Facebook将最终提供以下URL:
如果"MyApp用户"跟随其中一个Facebook链接,则可能会发生以下两种情况之一,具体取决于他们使用的浏览器...
MyApp股票浏览器用户:
如果用户安装了Android安装并使用了Android浏览器,那么事情就会很好,因为发生了以下事件......
MyApp非浏览器用户:
但是如果用户......
......然后这是主要问题,因为发生了以下事件......
客户端重定向
为了确认导致问题的重定向,我创建了一个名为"clientSideRedirector.htm"的非常简单的HTML页面.
<html><body><script>
window.location.href = "http://myapp.com/sharedpage";
</script></body></html>
Run Code Online (Sandbox Code Playgroud)
如果我的应用程序/非库存浏览器用户打开 …
为什么===不能和Swift中的String一起使用?我无法编译以下内容:
let string1 = "Bob"
let string2 = "Fred"
if string1 === string2 {
...
}
Run Code Online (Sandbox Code Playgroud)
并获得以下错误(在if行上):
二进制运算符'==='不能应用于两个'String'操作数
我希望在我的单元测试中能够做的是,执行了copyWithZone :,验证两个对象确实是一个具有不同指针的不同对象,即使它们的值相同.以下代码不起作用......
XCTAssertFalse(object1.someString === object2.someString)
如果有人知道另一种方式请告知.
我正在尝试解码来自第三方 API 的 JSON 响应,其中包含已进行 base64 编码的嵌套/子 JSON。
人为的示例 JSON
{
"id": 1234,
"attributes": "eyAibmFtZSI6ICJzb21lLXZhbHVlIiB9",
}
Run Code Online (Sandbox Code Playgroud)
PS"eyAibmFtZSI6ICJzb21lLXZhbHVlIiB9"是 { 'name': 'some-value' }base64 编码的。
我目前有一些代码可以对此进行解码,但不幸JSONDecoder()的是init,为了这样做,我必须重新实例化一个额外的内部,这并不酷......
人为的示例代码
struct Attributes: Decodable {
let name: String
}
struct Model: Decodable {
let id: Int64
let attributes: Attributes
private enum CodingKeys: String, CodingKey {
case id
case attributes
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(Int64.self, forKey: .id)
let encodedAttributesString = …Run Code Online (Sandbox Code Playgroud) 我有一个包含WebView的原生Android应用程序.我的所有HTML,js和css都已添加到assets文件夹中的Android项目中,所以我在Java代码中初始化我的WebView就像这样......
WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/index.htm");
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我需要使用jQuery getScript方法从JavaScript动态加载其他js文件...
var scriptUrl = "scripts/dynamicScript.js";
$.getScript(scriptUrl , function() { alert("Success"); })
.fail(function(e){ alert("failed: " + JSON.stringify(e)); });
Run Code Online (Sandbox Code Playgroud)
基本上脚本没有加载,我收到以下消息:
failed: {"readState":4,"responseText":"", "status":404, "statusText":"error"}
Run Code Online (Sandbox Code Playgroud)
我也为scriptUrl尝试了以下替代方案,并得到完全相同的结果和消息:
"/scripts/dynamicScript.js"
"./scripts/dynamicScript.js"
"android_asset/scripts/dynamicScript.js"
"../android_asset/scripts/dynamicScript.js"
"file:///android_asset/scripts/dynamicScript.js"
Run Code Online (Sandbox Code Playgroud)
我希望这可能与同源策略有关.任何帮助实现这项工作表示赞赏.
我现在也尝试了以下$ .getScript()的替代方法.
使用非异步'脚本'ajax调用.这导致与上面完全相同......
$.ajax({
url: scriptUrl,
dataType: 'script',
success: function() { alert("Success"); },
error: function(e){ alert("failed: " + JSON.stringify(e)); },
async: true
});
Run Code Online (Sandbox Code Playgroud)
并且还将脚本标签动态插入头部.这似乎不起作用(例如,如果我只是在dynamicScript.js中有一个警报,它从未见过)...
$("<script type='text/javascript' src='" + scriptUrl +"'></script>").appendTo("head");
Run Code Online (Sandbox Code Playgroud)
我可能也值得指出,如果我远程托管网站而不是本地资产,所有上述尝试都有效但是这不是一个可行的解决方案IE它可以工作,如果我实例化如下...
WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("http://remote-server/index.htm");
Run Code Online (Sandbox Code Playgroud) 我有一个小问题,我不知道如何解决.
在我们的多个项目中,我们希望将"将警告视为错误"(GCC_TREAT_WARNINGS_AS_ERRORS)更改为YES.
我们还想将Xcode默认项目设置"Build Active Architecture Only"(ONLY_ACTIVE_ARCH)YES保留给Debug和NORelease.
然而,这有一个主要的缺点.代码如......
NSUInteger bob = 12234;
NSLog(@"bob %lu", bob);
Run Code Online (Sandbox Code Playgroud)
应该产生以下类型的警告(因此我们的错误):
"NSUInteger"类型的值不应用作格式参数; 添加显式强制转换为'unsigned long'
但是,当开发人员在本地构建和测试时,他们不会遇到此警告/错误,但是当他们提交到我们的存储库并且我们xcodebuild从命令行继续运行时,会遇到警告并且他们的构建失败.这显然是相当令人沮丧的.
我认为这与使用Xcode时和使用xcodebuild命令行时构建的架构之间的区别有关.
我在这里上传了一个示例项目......
https://github.com/OliverPearmain/ArchitectureDependantCompileWarning
我已经包含了2个方案.如果您使用"ArchitectureDependantCompileWarning"(使用Debug构建配置,因此ONLY_ACTIVE_ARCH==YES)编译iPhone 6S模拟器,您将得不到任何警告,并且编译正常.如果您使用"ArchitectureDependantCompileWarning-FAILS"方案(使用Release构建配置,那么ONLY_ACTIVE_ARCH==NO),则会遇到警告并且编译失败.
我想以某种方式确保在为模拟器构建时始终遇到此警告ONLY_ACTIVE_ARCH==NO.这可能吗?
Segmentation fault: 11编译的时候总是报错。
我已经大量剥离了我的代码以识别导致问题的细微差别,并生成了下面的演示代码,该代码展示了完全相同的问题。
任何人都可以提出任何解决此问题的方法(这与我在代码注释中已经强调的不同)?
PS:这个 Swift 5 代码和 Xcode 11.7 和 Xcode 12 一起出现
// If we make this a class instead, it compiles! (but I want it to be a struct)
struct SomeStruct {
// If we remove either of these properties or change them to an Int, it compiles! (but I obviously need 2 strings)
let propertyA: String
let propertyB: String
}
protocol Protocol { }
enum Enumeration {
// If we remove this case, it …Run Code Online (Sandbox Code Playgroud)