Slow start for AVAudioPlayer the first time a sound is played

The delay seems to be related to instantiating AVAudioPlayer for the first time. If I load any audio, run [audioPlayer prepareToPlay] and then immediately release it, the load times for all of my other audio is very close to imperceptible. So now I’m doing that in applicationDidFinishLaunching and everything else runs well. I can’t find … Read more

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

If anyone is looking for a way to do this in Swift: Swift 3 introduces the Data type, with value semantics. To convert the deviceToken to a String, you can do as follows: func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let token = deviceToken.map { String(format: “%02.2hhx”, $0) }.joined() print(token) } Old answer using … Read more

Decode Base-64 encoded PNG in an NSString

You can decode a Base64 encoded string to NSData: -(NSData *)dataFromBase64EncodedString:(NSString *)string{ if (string.length > 0) { //the iPhone has base 64 decoding built in but not obviously. The trick is to //create a data url that’s base 64 encoded and ask an NSData to load it. NSString *data64URLString = [NSString stringWithFormat:@”data:;base64,%@”, string]; NSData *data … Read more

NSData to UIImage

Try this code. This worked for me. Saving the data. create path to save the image. let libraryDirectory = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0] let libraryURL = URL(fileURLWithPath: libraryDirectory, isDirectory: true) let fileURL = libraryURL.appendingPathComponent(“image.data”) convert the image to a Data object and save it to the file. let data = UIImageJPEGRepresentation(myImage, 1.0) try? data?.write(to: fileURL) retrieving … Read more

Iphone – How to encrypt NSData with public key and decrypt with private key?

I have tried RSA Encryption and Decryption for NSString and you may well modify it and make it work for NSData Add Security.Framework to your project bundle. ViewController.h code is as follows: #import <UIKit/UIKit.h> #import <Security/Security.h> @interface ViewController : UIViewController { SecKeyRef publicKey; SecKeyRef privateKey; NSData *publicTag; NSData *privateTag; } – (void)encryptWithPublicKey:(uint8_t *)plainBuffer cipherBuffer:(uint8_t *)cipherBuffer; … Read more