我正在尝试使用Retrofit 2.0对服务器进行HTTP POST
MediaType MEDIA_TYPE_TEXT = MediaType.parse("text/plain");
MediaType MEDIA_TYPE_IMAGE = MediaType.parse("image/*");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG,90,byteArrayOutputStream);
profilePictureByte = byteArrayOutputStream.toByteArray();
Call<APIResults> call = ServiceAPI.updateProfile(
RequestBody.create(MEDIA_TYPE_TEXT, emailString),
RequestBody.create(MEDIA_TYPE_IMAGE, profilePictureByte));
call.enqueue();
Run Code Online (Sandbox Code Playgroud)
服务器返回错误,指出文件无效.
这很奇怪,因为我试图在iOS上使用相同的格式上传相同的文件(使用其他库),但它上传成功.
我想知道使用Retrofit 2.0上传图像的正确方法是什么?
在上传之前我应该先将它保存到磁盘吗?
谢谢!
PS:我已经将改造用于其他不包含图像的Multipart请求,并且已成功完成.问题是当我试图在主体中包含一个字节时.
我想知道我们如何创建一个更大的中心UITabBar,如下图所示?真的很漂亮!!!!

在较旧版本的Alamofire中.这是我下载文件的方式
let destinationPath = Alamofire.Request.suggestedDownloadDestination( directory: .documentDirectory, domain: .userDomainMask);
Alamofire.download(.GET, urlString, destination: destinationPath)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
// print(totalBytesRead)
}
.response { request, response, _, error in
let downloadedFilePath = destinationPath(URL(string: "")!, response!);
NSUserDefaultsHelper.saveURL(downloadedFilePath, key: urlString);
completion(downloadedFilePath, true);
}
Run Code Online (Sandbox Code Playgroud)
但是现在在新版本中,我的代码完全无法使用,并且Alamofire库中没有类似的功能.
有什么想法吗?
我正在尝试UIViewController从Nib文件创建一个.在Google上我发现我只能从Nib加载UIView.
但有些人建议我可以创建一个Nib文件(UIView),其文件所有者设置为我们的ViewController.
这就是我做的,我没有崩溃,但视图没有显示.
编辑:试图viewcontroller像这样推
self.navigationController!.pushViewController(CoolViewController(), animated: true );
Run Code Online (Sandbox Code Playgroud)
但它被推动时仍显示黑屏
XCode 6.3 - 不使用故事板
我们如何在Alamofire 4.0的上传功能中添加身份验证标头?
下面是示例代码,但我认为没有办法在函数中添加标题.
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(unicornImageURL, withName: "unicorn")
multipartFormData.append(rainbowImageURL, withName: "rainbow")
},
to: "https://httpbin.org/post",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
Run Code Online (Sandbox Code Playgroud)
以前版本的alamofire支持直接添加标题,但不支持新标题.有任何想法吗?
我有一个启动器Activity加载和调整大位图的大小,因为它是打开时的背景.
每当按下后退按钮时,Activity就是destroyed.但我认为记忆尚未公布.
当我打开应用程序时,点击后退按钮再次打开它(反复),我会得到一个OutOfMemoryError.
我这个新手的问题,对不起,但我不知道我怎么释放每当记忆Activity是destroyed?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
//MARK - movingBackgroundImageView
movingBackgroundImageView = (ImageView) findViewById(R.id.movingBackgroundImageView);
movingBackgroundImageView.setColorFilter(Color.argb(255, 255, 255, 255));
movingBackgroundImageView.setScaleType(ImageView.ScaleType.MATRIX);
movingBackgroundImageView.setAlpha(0.28f);
prepareBackgroundAnimation();
}
private void prepareBackgroundAnimation() {
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
screenWidth = displaymetrics.widthPixels;
screenHeight = displaymetrics.heightPixels;
movingImageHeight = displaymetrics.heightPixels;
movingImageWidth = 1920.0 / 1080.0 * movingImageHeight;
bitmapImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.moving_background_image);
scaledBitmap = bitmapImage.createScaledBitmap(bitmapImage, (int) movingImageWidth, (int) movingImageHeight, false);
movingBackgroundImageView.setImageBitmap(scaledBitmap);
backgroundImageInBeginning …Run Code Online (Sandbox Code Playgroud) android out-of-memory android-memory android-studio android-bitmap
我将我的Xcode更新到最新版本,我注意到的一件事是截图图像尺寸变小.
在我使用模拟器内置的"保存屏幕截图"功能进行屏幕截图时更新它之前iPhone 6 Plus simulator.我会得到1920 * 1080,但现在图像尺寸只是414 * 736.
有什么想法吗?
对不起,这些问题
我在swift中有4个关于Selector的问题.
第一个问题
我想知道在swift中使用selector的正确方法是什么
closeBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Stop, target: self, action: Selector("closeBarButtonItemClicked:"));
Run Code Online (Sandbox Code Playgroud)
VS
closeBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Stop, target: self, action: "closeBarButtonItemClicked:");
Run Code Online (Sandbox Code Playgroud)
我们应该立即使用Selector("methodName:")或"methodName:"吗?
两种方式都有效但哪一种方法正确?
第二个问题
我们如何在Swift中使用参数调用函数?假设我想调用这样的函数
func methodName(parameterOne : String, parameterTwo: String)
Run Code Online (Sandbox Code Playgroud)
第三个问题
我们如何在swift中使用Selector调用类型方法?甚至可能吗?
class SomeClass {
class func someTypeMethod() {
// type method implementation goes here
}
}
Run Code Online (Sandbox Code Playgroud)
第四个问题
在Selector中函数名后面的冒号的目的是什么?
每当我打开应用程序时,我都想检查自动可续订订阅状态.
这是为了确保用户仍然订阅了该服务.我该如何实现这一目标?
有什么想法吗?谢谢
PS:我正在使用 SwiftyStoreKit
我想知道当 以编程方式完成更改时,我们如何检测选定的TabBar项目或索引何时更改?
self.tabBarController.selectedIndex = 1;
Run Code Online (Sandbox Code Playgroud)
这两个委托函数仅在用户选择tabBar项时检测更改.当以编程方式完成对selectedIndex的更改时,它不会触发.
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
println("tabBarController didSelectViewController")
}
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
println("tabBar didSelectItem")
}
Run Code Online (Sandbox Code Playgroud)