Tag: objective c

当正文中有表情符号时,HTTP POST失败

我正在做任何用户在uiTextField中input的HTTP POST。 文本被捕获在NSString中,然后被添加到一个NSDictionary。 然后它被转换为JSON,最后转换为UTF8的NSData作为HTTP Body。 如果用户input纯文本,这完美的作品。 但是,如果用户input了表情符号,那么它会一直工作到HTTP POST自身的位置。 从NSString到NSDict到JSON的转换都很好。 它甚至被转换为UTF8的NSData。 但是当POST被调用时会抛出一个错误。 这是我的代码: 这实际上是当我试图将JSON转换为NSData(UTF8)时发生的,所以我可以将它作为HTTP Body传递给我从应用程序到后端的POST。 以下是引发错误的区域: NSString *jsonPushData = [self mutDictToJson:pushData]; NSLog(@"sendMessage:jsonPushData has: %@",jsonPushData); //NSData *requestBodyData = [NSData dataWithBytes:[jsonPushData UTF8String] length:[jsonPushData length]]; NSData *requestBodyData = [NSData dataWithBytes:[jsonPushData UTF8String] length:[jsonPushData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: restApiUrl cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 10.0]; NSLog(@"sendMessage:requestBodyData has: %@ with length: […]

React Native:无法连接到开发服务器

我有一个非常简单的React Native项目,我正在努力工作。 这是一个iOS项目,简单地将RCTRootView添加到UIViewController。 当我从Xcode运行应用程序时,出现错误的红色屏幕: Could not connect to development server. Ensure the following: – Node server is running and available on the same network – run 'npm start' from react-native root – Node server URL is correctly set in AppDelegate AppDelegate.h @property (strong, nonatomic) RCTRootView *rootView; application: didFinishLaunchingWithOptions: AppDelegate.m application: didFinishLaunchingWithOptions: NSURL *jsCodeLocation = [NSURL […]

将数据从iPhone应用程序发送到Node.js Web服务器

我把这个代码用于制作一个sinatranetworking服务器,并使用express来创build我自己的Node.js版本。 然后我得到这个代码在iPhone上工作,从服务器获取数据。 iphone应用程序发送'/sushi.json'的HTTP请求,服务器用app.get('/sushi.json', function(request, response)) 。 然后服务器发送一个JSONstring回iOS应用程序,然后parsing成一个数组,以便它可以使用它。 但是如果我想发送数据到服务器呢? 在iPhone应用程序中,我将如何构build并发送JSONstring,服务器将如何监视它? 另外,我不需要使用socket.io来获得这个工作。 这是应该在这里使用的东西吗?

从iPhone Application Expressjs / Nodejs后端发送JSON发布数据

这是我的代码发送一个postjs后端请求。 CLLocation* location = [locationManager location]; CLLocationCoordinate2D coord = [location coordinate]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://50.63.172.74:8080/points"]]; //[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; NSDictionary* jsonDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:coord.latitude], @"lat", [NSNumber numberWithFloat:coord.longitude], @"lng", nil];//dictionaryWithObjectsAndKeys:coord.latitude, nil] NSString *postString; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of […]

有没有办法将Node.JS与Objective-C / iPhone SDK集成?

我已经在JSON中为我的node.js中间件实现了一个实时应用程序。 我想知道是否有任何方法为iPhone准备客户端?

在Objective-C解密节点j中进行encryption

我正在encryption一些文本我想发送到服务器,我没有问题encryption,并在Objective-C解密,但是当我发送到nodejs服务器的结果解密它永远不会正确的encryption数据总是来相同…我认为问题是我如何使用encryption库,这里是我的Xcode代码: NSString * key =@"1234567890123456"; NSString * url = @"http://flystory.herokuapp.com/register"; NSString *post = @"hola mundo!!!!!!!!!!"; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSLog(@"%@",[[NSString alloc] initWithData:postData encoding:NSASCIIStringEncoding]); NSError *e; CCCryptorStatus err; postData = [postData dataEncryptedUsingAlgorithm:kCCAlgorithmAES128 key:key options:kCCOptionECBMode error:&err]; NSLog(@"%@",[[NSString alloc] initWithData:postData encoding:NSASCIIStringEncoding]); NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL […]

Objective-C HMAC 256与Node.js的区别

伙计们, 我正在尝试生成Hmac256摘要,但是我在node.js和objective-c中获得了不同的结果。 不知道为什么。 这是我认为是正确的节点代码。 var crypto = require('crypto') var result = crypto.createHmac('sha256', 'mykey').update('mydata', 'utf-8').digest('base64'); 这是我的Objective-C代码: const char *cKey = [@"mykey", cStringUsingEncoding:NSUTF8StringEncoding]; const char *cData = [@"mydata" cStringUsingEncoding:NSUTF8StringEncoding]; unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [Base64 encode:HMAC]; 任何人有任何想法的差异的原因可以是?

在Cocoa / OSX应用程序中封装node.js

好的,这是什么: 我不想在node.js中编写一个OSX应用程序 – 该应用程序几乎完成,在Objective-C / Cocoa中为100% 我不想桥接Objective-C和node.js 我希望能够执行一个js / node.js脚本,无论用户是否已经预先安装了node.js二进制 那么,有没有什么已知的方法? 你会build议什么?

我如何插入一个datetypes到iOS Swift的MongoDB(通过JSON和Node.js)

有没有人设法用iOS Swift(或Objective C)在MongoDB中插入datetypes? 我知道我可以像这样存储一个string: let now = NSDate() let nowISO8601 = ISO8601Format.stringFromDate(now) 但是真的,我想要构造一个有效的JSON对象,并在插入到MongoDB中时生成一个datetypes。 下面是我的Swift代码的简化版本,通过Node.js Web服务发布到MongoDB: let dateData = ["some_date" : nowISO8601] if NSJSONSerialization.isValidJSONObject(dateData){ let url = NSURL(string: "http://mynodejsurl") var request = NSMutableURLRequest(URL: url!) var data = NSJSONSerialization.dataWithJSONObject(dateData, options: nil, error: nil) request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.HTTPMethod = "POST" request.HTTPBody = data let task = session.dataTaskWithRequest(request, completionHandler: […]

错误:多部分数据的意外结束] storage.Error:express.js-iOS(Objective-C)应用程序中的

我试图find这个问题的解决scheme,无法在node.js / express.js和iOS应用程序中find任何东西。 我的客户有要求不要使用任何第三方库。 所以,我不使用AFNetworking。 任何帮助,或者如果有人可以告诉为什么错误即将到来将不胜感激。 我正在尝试发送多部分表单数据,图像与文本。 每当我做POST我得到错误:多部分数据的意外结束。 iOS中POST的代码: NSURL *url = [NSURL URLWithString:@"http://172.16.0.5:8080/upload"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"YOUR_BOUNDARY_STRING"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n–%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"photo\"; filename=\"%@.jpg\"\r\n", self.path] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: […]