nsdata

Creating NSData from NSString in Swift

牧云@^-^@ 提交于 2019-11-26 19:34:49
I'm trying to ultimately have an NSMutableURLRequest with a valid HTTPBody , but I can't seem to get my string data (coming from a UITextField ) into a usable NSData object. I've seen this method for going the other way: NSString(data data: NSData!, encoding encoding: UInt) But I can't seem to find any documentation for my use case. I'm open to putting the string into some other type if necessary, but none of the initialization options for NSData using Swift seem to be what I'm looking for. In Swift 3 let data = string.data(using: .utf8) In Swift 2 (or if you already have a NSString instance)

NSData and Uploading Images via POST in iOS

六眼飞鱼酱① 提交于 2019-11-26 18:24:56
I have been combing through the many many posts about uploading images via POST in iOS. Despite the wealth of information on this topic, I cannot manage to correctly upload JPEG data taken from my iPhone Simulator Photo Library. The data, once on the server, is just a huge string of hexidecimal. Shouldn't NSData just be a byte stream? I don't get whats going on with all the hex, or why this code seems to work for everyone else. Here is the code in question: -(void)uploadWithUserLocationString:(NSString*)userLocation{ NSString *urlString = @"http://some.url.com/post"; // set up the form keys

Correct way to load image into UIWebView from NSData object

元气小坏坏 提交于 2019-11-26 18:19:31
问题 I have downloaded a gif image into an NSData object (I've checked the contents of the NSData object and it's definitely populated). Now I want to load that image into my UIWebView. I've tried the following: [webView loadData:imageData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; but I get a blank UIWebView. Loading the image from the same URL directly works fine: NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]]; [imageView loadRequest:request];

How can I convert my device token (NSData) into an NSString?

倖福魔咒の 提交于 2019-11-26 17:54:49
问题 I am implementing push notifications. I'd like to save my APNS Token as a String. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { NSString *tokenString = [NSString stringWithUTF8String:[newDeviceToken bytes]]; //[[NSString alloc]initWithData:newDeviceToken encoding:NSUTF8StringEncoding]; NSLog(@"%@", tokenString); NSLog(@"%@", newDeviceToken); } The first line of code prints null. the second prints the token. How can

Split NSData objects into other NSData objects of a given size

拟墨画扇 提交于 2019-11-26 17:36:20
问题 I have an NSData object of approximately 1000kB in size. Now I want to transfer this via Bluetooth. It would be better if I have, let's say, 10 objects of 100kB. It comes to mind that I should use the -subdataWithRange: method of NSData. I haven't really worked with NSRange. Well, I know how it works, but I can't figure out how to read from a given location with the length: 'to end of file'... I've no idea how to do that. Some code on how to split this into multiple 100kB NSData objects would

Saving [UIColor colorWithPatternImage:image] UIColor to Core Data using NSKeyedArchiver

∥☆過路亽.° 提交于 2019-11-26 17:08:40
问题 I'm unable to create an NSData object from a UIColor (with a pattern) created with the factory method [UIColor colorWithPatternImage:image] works fine for standard UIColor objects. Wondering if there is another way to save a UIColor with a pattern into Core Data. I am using the following code to archive the UIColor (with a pattern)... - (id)transformedValue:(id)value { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value]; return data; } and these are the errors I'm receiving... -

How to share NSData or phasset video using Facebook iOS SDK 4.0 FBSDKShareDialog

孤街浪徒 提交于 2019-11-26 16:47:30
问题 I noticed you can share NSData video to facebook messenger simply: NSData *videoData = [NSData dataWithContentsOfURL:localVideoUrl]; [FBSDKMessengerSharer shareVideo:videoData withOptions:options]; But I’m having difficulties doing the same when sharing to facebook feed using local video file or phasset. FBSDKShareVideo *video = [FBSDKShareVideo videoWithVideoURL:localVideoUrl]; FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init]; [content setVideo: video];

Send and receive NSData via GameKit

依然范特西╮ 提交于 2019-11-26 16:19:32
问题 I'm trying to send some NSData over Bluetooth through GameKit . While I've got GameKit set up and are able to send small messages across, I now would like to expand and send across whole files. I've been reading that you have to split large files up into packets before sending them across individually. So I decided to create a struct to make it easier to decode the packets when they're received at the other end: typedef struct { const char *fileName; NSData *contents; int fileType; int

Converting NSData to base64

好久不见. 提交于 2019-11-26 16:12:15
How to convert NSData to base64 . I have NSData and want to convert into base64 how can I do this? EDIT As of OS X 10.9 / iOS 7, this is built into the frameworks. See -[NSData base64EncodedDataWithOptions:] Prior to iOS7/OS X 10.9: Matt Gallagher wrote an article on this very topic. At the bottom he gives a link to his embeddable code for iPhone. On the mac you can use the OpenSSL library, on the iPhone he writes his own impl. joshrl //from: http://cocoadev.com/BaseSixtyFour + (NSString*)base64forData:(NSData*)theData { const uint8_t* input = (const uint8_t*)[theData bytes]; NSInteger length

Determine MIME Type of NSData Loaded From a File

☆樱花仙子☆ 提交于 2019-11-26 15:55:48
问题 For various reasons I am intercepting http requests and loading content from files in my app's document directory using NSURLProtocol. Part of the process involves loading an NSData object, which could be anything from an html file to a jpeg image. NSURLProtocol requires setting a mimetype. Is there an API in the iPhone-SDK to determine the mimetype of the file or NSData content? 回答1: Perhaps you could download the file and use this to get the file's MIME type. + (NSString*)