用多个参数在swift中上传图像

我正尝试使用swift将图像上传到后端客户端。 麻烦是我似乎无法得到格式正确的httpbody。 我不想使用多部分的forms上传,因为我不知道如何处理在后端。 这是我有的代码..它不工作,当我在网上查看图像不显示,它只是像70kb,我知道绝对不是多大的形象。 var bodyString: String = "session_id=\(session_id)&location_id=\(location_id)" bodyString = bodyString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! var body = NSMutableData.alloc() body.appendData(bodyString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!) if image != nil{ var imageData = UIImageJPEGRepresentation(image,0.5) body = NSMutableData.alloc() //var imageDataString = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) bodyString = "session_id=\(session_id)&location_id=\(location_id)&image_data=" bodyString = bodyString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! body.appendData(bodyString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!) var imageString = "&image_data=\(imageData)" body.appendData(imageData) } req.HTTPBody = body 更新:所以我决定去base64的路线,但它似乎仍然没有工作我认为,因为我编码它作为ntf8string这是正确的方式做到这一点? var […]

在UIActionSheet上添加UIView作为子视图

我正在项目中,我想要显示UIActionsheet三个button更改,取消和完成,在标题的地方,我想把UIView有一些标签。 我已经创build了dynamic的UIView,我把它添加到动作表,但它隐藏在button后面,我试图通过所有可能的方式setFrame,但我无法find解决scheme。 我想把这个UIView放在UIActionsheet的顶部,然后是button。 如果您有任何疑问,请随时发表评论。 这是我的代码: -(IBAction)tapbutton:(id)sender { Lablesubview *view = [[Lablesubview alloc]init]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Change" otherButtonTitles:@"Done",nil]; [actionSheet addSubview:view]; [actionSheet showInView:self.view]; }

iOS CustomTableViewCell:元素不能正确alignment

我在构build应用程序时第一次学习iOS 。 在其中一个要求中, UITableViewCell需要看起来像 (PS:这只是一个devise,没有代码是为此写的) 但是,当我devise我的UITableViewCell ,它看起来像 和生成这个代码看起来像 – (void)setTransactionCell:(TransactionCell *)transactionCell transactionModel:(TransactionModel *)transactionModel { transactionCell.dateOfMonth.image = [self getDayImage:[UIImage imageNamed:@"1"]]; transactionCell.dayOfWeek.image = [self getDayImage:[UIImage imageNamed:@"Sun"]]; transactionCell.name.text = transactionModel.name; transactionCell.name.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15]; transactionCell.amount.text = transactionModel.amount; transactionCell.amount.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15]; transactionCell.categoryImage.image = [self getCategoryImage:[UIImage imageNamed:transactionModel.category]]; transactionCell.imageView.contentMode = UIViewContentModeCenter; } – (UIImage *)getDayImage: (UIImage *) image […]

使用#define和clang为info.plist创build版本号变体?

几年前,在编译GCC时,在#include.h文件中定义的以下内容可以在info.plist中预处理: #define MAJORVERSION 2 #define MINORVERSION 6 #define MAINTVERSION 4 <key>CFBundleShortVersionString</key> <string>MAJORVERSION.MINORVERSION.MAINTVERSION</string> …将变成“2.6.4”。 这是因为海湾合作委员会支持“传统”的国旗。 (请参阅Xcode中的技术说明TN2175 Info.plist文件使用C预处理器 ,在“在macros扩展过程中消除令牌之间的空白”下) 但是,快进到2016和Clang 7.0.2(Xcode 7.2.1)显然不支持“-traditional”或“-traditional-cpp”(或正确支持),产生以下string: "2 . 6 . 4" (请参阅错误12035 – 预处理程序在macros扩展中插入空格,注释4 ) 因为有很多不同的变体(CFBundleShortVersionString,CFBundleVersion,CFBundleGetInfoString),所以最好解决这个叮当问题,并定义一次,然后连接/串联这些部分。 什么是现在这样做的普遍接受的模式? (我目前正在build立在MacOS上,但IOS的工作模式是一样的)

Appium,Instruments在启动时坠毁

当我将Xcode从6.4更新到7.2时,我的Appium UI Automation停止工作,仪器崩溃。 Appium:1.4.13 Xcode:7.2 这里是错误日志: info: Launching instruments info: [debug] Attempting to run app on iPhone 6 (8.4) info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w "iPhone 6 (8.4)" /var/folders/23/nmp6lms102vg0s25m1322t400000gp/T/116125-731-112rfi4/Time.app -e UIASCRIPT "/Users/bogdan.shubravyi/Library/Application Support/appium/bootstrap/bootstrap-f062718992d59810.js" -e UIARESULTSPATH /tmp/appium-instruments info: [debug] And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/thirdparty/iwd7/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/thirdparty/iwd7"} info: [debug] And launch timeouts (in […]

提供Quadtree GPS数据到应用程序的最佳select?

我们有> 25 MB的静态四叉树数据,我们希望作为跨平台应用程序的一部分提供,然后可以通过应用程序代码进行search,以获取接近用户当前GPS位置的位置的详细信息。 我们希望在不加载所有数据的情况下快速search数据,理想情况下不需要重新发明轮子。 我们已经看过在SQLite中使用R-Trees提供数据库,这听起来像是理想的,但显然这些在Android提供的SQLite版本中不可用。 运行我们自己的Android版SQLite(包括R-Tree结构)听起来有很多痛苦,但我们希望了解其他人的经验。 我们可以创build一个文件系统模型,但是我们的数据可能非常大,而且我们觉得我们可能会以这种方式误用文件系统。 我们希望可能有一些其他文件格式已经为此目的而devise,可能还有java / obj-c库来search这个文件。 任何人都可以指出我们这样的事情吗? 另一个明显的解决scheme是创build我们自己的文件格式和search系统,但这可能是很多工作。 该应用程序实际上是一个cordova / phonegap应用程序,将可用于iOS和Android,但它不是一个问题编写一个本地插件为每个平台来处理这个。 提前致谢

FloatValue与textField中的2位小数

在我的核心数据应用程序中,我从3个UITexFields保存3个浮点数。 要做到这一点,我不得不将它们转换为string。 现在的问题是,值被舍入为.0 。 我该怎么做? nyTankning.liter = (textFieldLiter.text as NSString).floatValue nyTankning.kronor = (textFieldKronor.text as NSString).floatValue nyTankning.literpris = (textFieldLiterpris.text as NSString).floatValue

显示所有标签滚动选项(屏幕上应该只有4个标签)

我是iOS开发的新手。 我到目前为止所做的是如下。 创build新项目 删除了所有控制器并添加了View Controller。 在ViewController拖动ScrollView 在ScrollView拖动Tab Bar 在Tab Bar拖动7个Tab Bar Item 。 现在,当我执行这个项目,我有屏幕上的所有7个标签不好看。 所以我打算只显示4个选项卡,如果用户水平滚动,用户可以滚动并看到其余选项卡。 所以,我想实现的是以编程方式在ScrollView中设置一些参数,它将只显示前四个选项。 任何想法/build议要做?

保存希伯来语文本NSUserDefaults返回奇怪的编码

我将希伯来文保存到NAMutableArray,然后将其保存到NSUserDefalts,如下所示: numOfWallPosts++; NSString *tempKeyToStore = [NSString stringWithFormat:@"wall_post_%d", numOfWallPosts]; // wall_post_%d NSMutableArray *tempArray = [[NSMutableArray alloc] init]; [tempArray addObject:currentOwner]; [tempArray addObject:currentTitle]; [tempArray addObject:currentText]; [tempArray addObject:currentDate]; [tempArray addObject:currentTime]; [tempArray addObject:currentImageURL]; [tempArray addObject:currentWallID]; [self.sharedPrefs setObject:tempArray forKey:tempKeyToStore]; [self.sharedPrefs synchronize]; 当我想要得到希伯来语的文本,我得到这样的文字: Wall messages: ( "\U05de\U05e2\U05e8\U05db\U05ea", "\U05ea\U05e8\U05d2\U05d9\U05dc \U05e4\U05d9\U05e7\U05d5\U05d3 \U05d4\U05e2\U05d5\U05e8\U05e3", "\U05d0\U05d6\U05e2\U05e7\U05ea \U05ea\U05e8\U05d2\U05d5\U05dc \U05d1\U05e9\U05e2\U05d4 19:05", "27/05/13", "13:16", "http://blabla……", 9 ) 我试图用NSUTF8StringEncoding格式化文本,用NSUTF8StringEncoding格式化文本,我仍然用这种方法得到文本。 我可以用正确的方式保存文本还是将其编码回适当的希伯来文? 编辑:这是如此奇怪,虽然文字保存奇怪,我把它拉回来,我得到正确的文字。 […]

NSString中的内存泄漏stringWithUTF8String:启用ARC

在我的应用程序中,我启用了ARC。 但是在我的应用程序中,下面的行根据仪器给我内存泄漏。 它在ios 7.0中。 -(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self; } 更新 但在我的应用程序,如果我做下面的东西,它不显示任何泄漏。 但我不能将项目添加到variables。 -(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc] init] copy]; //No Leak return self; } – NSString *utfString =[NSString stringWithUTF8String:(const char *)attr->children->content];//Leak – -(NSObject*)createObjectForClass:(NSString*)className{ Class […]