nsdata

Writing/reading to paths with interleaved double dots fails on iOS 8

筅森魡賤 提交于 2019-12-13 04:59:25
问题 This code fails on iOS 8, although it would work on iOS 7 UIImage *imageTest = ... NSString *file = @"../Documents/Test.png"; NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: file]; [UIImagePNGRepresentation(imageTest) writeToFile: fullpath atomically: YES]; UIImage *image = [UIImage imageNamed: file]; On iOS 8 I need to use this instead NSString *file = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

NSData object from created from unsigned 64-bit integer is reversed

拥有回忆 提交于 2019-12-13 04:35:58
问题 In Xcode 5.0.2 on OS X 10.9.1: uint64_t data = 0x6ffa9e58938d7f5d; NSData *nsdataObj = [NSData dataWithBytes:&data length:8]; NSLog(@"%@", nsdataObj); Output: <5d7f8d93 589efa6f> How/why is the data getting reversed? 回答1: In this brave new world of Intel Macintoshes*, your integers are stored in memory in an absolutely bizzare fashion known as "little-endian byte order". That means that, unlike the more reasonable, human-readable format in which you wrote your number, the Least Significant

How to convert custom array to NSData in swift?

匆匆过客 提交于 2019-12-13 04:09:28
问题 I am trying to save data by NSUserDefaults . Here is my code @IBAction func saveBtn(sender: AnyObject) { var userName = nameLbl.text UserInfo.append(User(name: userName)) NSUserDefaults.standardUserDefaults().setObject(UserInfo, forKey: "UserInfo") userName = "" } But when i click on save button, it is showing Attempt to set a non-property-list object . I think, UserInfo array need to convert as NSData . Please tell me how can i do that? 回答1: You need to make your custom object conform to the

How save images in home directory?

安稳与你 提交于 2019-12-13 04:01:42
问题 I am making an application in which i have use Json parsing. With the help of json parsing i get photo url which is saved in string. To show images in my cell i use this code NSString *strURL=[NSString stringWithFormat:@"%@", [list_photo objectAtIndex:indexPath.row]]; NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: strURL]]; CGRect myImage =CGRectMake(13,5,50,50); UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImage]; [imageView setImage:

iPhone pushNotification DeviceToken - How to “decrypt”

喜夏-厌秋 提交于 2019-12-13 02:56:01
问题 I've already managed to get the devicetoken from APNs. It's type of NSData. So i want to write this deviectoken into my mysql db. I've already tried to convert it to a string without luck. That was my way: NSString *tokenTMP = [[NSString alloc] initWithData:devToken encoding:NSASCIIStringEncoding]; If i have the deviceToken in a readable format. How do i use the token in php to send a request to the apns server? thanks a lot! 回答1: I added the following category to NSData - (NSString*)

Unit test method with NSData dataWithContentsOfURL

自作多情 提交于 2019-12-13 01:39:42
问题 I am developing an iOS app and I am trying to do it with test-driven development . I've been reading a lot on the subject and one of the things I came across in a book is that tests are supposed to be fast, repeatable and reliable . As a consequence, when writing a test for networking code, the test should "simulate" the network, so that it can be executed regardless of network availability. In my code I have a method that retrieves an image from the internet with a URL, scales it and stores

ios awkard image loading (url to nsdata to uiimage to uiimageview)

女生的网名这么多〃 提交于 2019-12-13 00:12:53
问题 I need you to humor me during this question. This is somewhat pseudo code because the actual situation is quite complex. I wouldn't load an image this way unless I needed to. Assume that I need to. NSURL *bgImageURL = [NSURL URLWithString:@"https://www.google.com/images/srpr/logo3w.png"]; UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:bgImageURL]]; [self.anIBOutletOfUIImageView setImage:img]; but I crash out with -[__NSCFData _isResizable]: unrecognized selector sent to

Create NSData by interpreting NSString as hex digits

走远了吗. 提交于 2019-12-12 19:55:20
问题 Edit1: rob mayoff'answer is wonderful.And this is my own: -(NSData *)change:(NSString *)hexString { int j=0; Byte bytes[[hexString length]]; for(int i=0;i<[hexString length];i++) { int int_ch; unichar hex_char1 = [hexString characterAtIndex:i]; int int_ch1; if(hex_char1 >= '0' && hex_char1 <='9') int_ch1 = (hex_char1-48)*16; else if(hex_char1 >= 'A' && hex_char1 <='F') int_ch1 = (hex_char1-55)*16; else int_ch1 = (hex_char1-87)*16; i++; unichar hex_char2 = [hexString characterAtIndex:i]; int

iphone - data signing using NSData of the private key

大兔子大兔子 提交于 2019-12-12 17:04:53
问题 I am working on a e-banking iphone application. I am using WSS with XML-Signature to sign the requests to the customer's SOAP server. Since the iPhone device can not be trusted (due to jail-breaking), the customer requirement is to manually encrypt the RSA key pair (using AES128) before storing the keys into keychain. From what I have found so far, the keys are automatically added to the keychain when generated. So my idea is to extract the data afterwards (the same way the public key is

What is Swift enum byte representation?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 14:30:03
问题 I have the following enum: enum Enum: UInt8 { case A = 0x00 case B = 0x01 case C = 0x10 } I use the following code to convert it to NSData : var value = Enum.C let data = NSData(bytes: &value, length: 1) Naturally, I expect data to contain 0x10 , however, it contains 0x02 . For Enum.A it contains 0x00 and for Enum.B it contains 0x01 . To me, it looks like it stores an index of the value instead of its actual raw data. Could someone explain this behavior? P.S. If I use rawValue it works