Recent Comments

There are a total of 555 comments on this site.
Below are the most recent 30 of them, newest at the top.

Jay Versluis on How to share things with a UIActivityViewController

Saturday, 9th September 2017

Hi Tux, I did some investigating, and the demo code runs fine as is on my iOS 9 device, sharing an image to the camera roll without a hitch. On iOS 10 however, I got a crash with the following explanation:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
After fixing that, it shared the image as it should. I've explained how to add this key here: http://pinkstone.co.uk/what-is-the-nsphotolibraryusagedescription-key/. I've also updated my Demo Project to include this key now, it should work fine with iOS 10 now.

TuxLR on How to share things with a UIActivityViewController

Saturday, 9th September 2017

Hy, Using Xcode 8.3.3 and iPad (10.3.3), the image sharing does not work at all (there is just no image .. even not a blank or corrupted image ..) If you have any idea ? Anyway, thank you for your code ! Tux

Jay Versluis on How to use Swift classes in Objective-C

Tuesday, 15th August 2017

:-)

Chris Pa on How to use Swift classes in Objective-C

Sunday, 13th August 2017

Thanks! Best tutorial for this topic out there <3

Jay Versluis on Tip: How to download apps again after changing the region of your Apple ID (for free)

Thursday, 3rd August 2017

Indeed, In-App purchases that you've previously bought in another country will also work.

Jared on Tip: How to download apps again after changing the region of your Apple ID (for free)

Tuesday, 1st August 2017

Hi, any chance you tried to redownload any in-app purchases?

Jay Versluis on How to create infinite loops in Objective-C and C

Tuesday, 18th July 2017

Very good point Jayesh! You can exit loops at any time using the break statement. For example:

for ( ; ; ) {
    if (i == 47) {
        break;
    }
}
This works for finite loops as well of course.

Jayesh lathiya on How to create infinite loops in Objective-C and C

Tuesday, 18th July 2017

How to exit from infinite loop?

Jay Versluis on How to use Swift classes in Objective-C

Friday, 28th April 2017

Hi Param, you can change your Avatar picture anytime by heading over to gravatar.com and associating the email with which you leave comments.

Param on How to use Swift classes in Objective-C

Wednesday, 26th April 2017

didn't liked the picture next to comment

Param on How to use Swift classes in Objective-C

Wednesday, 26th April 2017

Great tutorial :)

Jay Versluis on How to fix "Couldn't communicate with a helper application" in Xcode 7

Saturday, 22nd April 2017

Excellent, thank you for sharing!

Adolfo Frias on How to fix "Couldn't communicate with a helper application" in Xcode 7

Tuesday, 18th April 2017

Worked for the latest update to Xcode 8.3.1! Thanks

Nive on How to fix "Couldn't communicate with a helper application" in Xcode 7

Monday, 6th March 2017

Thanks works for me!!

Stev on How to fix "Couldn't communicate with a helper application" in Xcode 7

Friday, 3rd March 2017

Jeesh, thanks. Never deny anything to an Apple app...

sagarsneh on How to fix "Couldn't communicate with a helper application" in Xcode 7

Sunday, 12th February 2017

Thanks!

Jay Versluis on How to use UIPasteboard to share data with iOS

Sunday, 5th February 2017

Excellent, thanks for sharing!

Paul on How to use UIPasteboard to share data with iOS

Sunday, 5th February 2017

Ah, I got it to work! I was using NSData but then found I did not need to do that as can use .image directly :-) THANKS ;-)

  //var myData = NSData()
        
  //self.textDocumentProxy.insertText(String(myData.length))
        
 // myData = NSData(data: UIImagePNGRepresentation(UIImage(named: "mymoji")!)!)
        
//UIPasteboard.general.setData(myData as Data, forPasteboardType:"com.mycom.mymoji")
        
UIPasteboard.general.image = UIImage(named: "mymoji")
        
self.textDocumentProxy.insertText(String(myData.length))
        
if (UIPasteboard.general.hasImages) {
            
    self.textDocumentProxy.insertText("Image in pasteboard");
            
 }
 else {
            
  self.textDocumentProxy.insertText("no image");
 }

Jay Versluis on How to use UIPasteboard to share data with iOS

Saturday, 4th February 2017

I would imagine UIPasteboard doesn't mind custom keyboards. How are you setting the image? Can you retrieve it without checking hasImages?

Paul on How to use UIPasteboard to share data with iOS

Saturday, 4th February 2017

Should this work on custom keyboards? I cannot get an image into general pasteboard, hasimages always returns false?

Jay Versluis on How to load different Storyboards for different versions of iOS in Xcode 5

Sunday, 29th January 2017

Glad you got it working :-)

John on How to load different Storyboards for different versions of iOS in Xcode 5

Saturday, 28th January 2017

So using your method, I edited to show the Start Controller to allow the user to show the options, if they do not set them, at all... just a simple else if added... code below for reference...

UIStoryboard *storyboard = nil;
        NSUserDefaults *defaultimperial = [NSUserDefaults standardUserDefaults];
        NSUserDefaults *defaultmetric = [NSUserDefaults standardUserDefaults];
        
        if ([defaultimperial boolForKey:@"unitSwitchImperial"])
        {
            // load imperial storyboard
            storyboard = [self grabStoryboardImperial];
        }
        else if ([defaultmetric boolForKey:@"unitSwitchMetric"])
        {
            // load metric storyboard
            storyboard = [self grabStoryboardMetric];
        }
         else
        {
            // load start storyboard
            storyboard = [self grabStoryboardStart];
        }
        // show the storyboard
        self.window.rootViewController = [storyboard instantiateInitialViewController];
        [self.window makeKeyAndVisible];
Then added the extra storyboard like this...
- (UIStoryboard*)grabStoryboardMetric {
    
    return [UIStoryboard storyboardWithName:@"iPhoneMetric" bundle:nil];
}

- (UIStoryboard*)grabStoryboardImperial {
    
    return [UIStoryboard storyboardWithName:@"iPhoneImperial" bundle:nil];
}

- (UIStoryboard*)grabStoryboardStart {
    
    return [UIStoryboard storyboardWithName:@"start" bundle:nil];
}
Again, thanks for all your help!

John on How to load different Storyboards for different versions of iOS in Xcode 5

Saturday, 28th January 2017

Your method is much more elegant than mine... Thanks for all your effort... it works!

John on How to load different Storyboards for different versions of iOS in Xcode 5

Saturday, 28th January 2017

If anyone is interested... I solved this using the following code...

if([defaultimperial boolForKey:@"unitSwitchImperial"])
        {
            /* Executes when the boolean expression is true */
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhoneImperial" bundle:[NSBundle mainBundle]];
            UIViewController *vc =[storyboard instantiateInitialViewController];
            
            // Set root view controller and make windows visible
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            self.window.rootViewController = vc;
            [self.window makeKeyAndVisible];
            NSLog(@"Imperial Storyboard");
        }
        
        else if([defaultmetric boolForKey:@"unitSwitchMetric"])
        {
            /* Executes when the boolean expression is true */
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhoneMetric" bundle:[NSBundle mainBundle]];
            UIViewController *vc =[storyboard instantiateInitialViewController];
            
            // Set root view controller and make windows visible
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            self.window.rootViewController = vc;
            [self.window makeKeyAndVisible];
            NSLog(@"Metric Storyboard");
        }
        
        else
        
        {
            /* executes when the none of the above condition is true */
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"start" bundle:[NSBundle mainBundle]];
            UIViewController *vc =[storyboard instantiateInitialViewController];
            
            // Set root view controller and make windows visible
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            self.window.rootViewController = vc;
            [self.window makeKeyAndVisible];
            NSLog(@"Start Storyboard");
            
        }

Jay Versluis on How to load different Storyboards for different versions of iOS in Xcode 5

Saturday, 28th January 2017

Hi John, your logic is sound and it's definitely possible. Your code is correct too as far as I can see, there's just one small thing when it comes to checking the user defaults. In applicationDidFinishLaunching, you're saying "if the BOOL isn't set, then set it". This overrides the value every time the app starts, even if the user has chosen metric. What you want to do instead, "if the BOOL is set, load the imperial storyboard. And if the BOOL is not set, then load the metric storyboard". In code this could look something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = nil;
    NSUserDefaults *defaultimperial = [NSUserDefaults standardUserDefaults];
    
    if ([defaultimperial boolForKey:@"unitSwitchImperial"]) {
        // load imperial storyboard
        storyboard = [self grabStoryboardImperial];
        
    } else {
        // load metric storyboard
        storyboard = [self grabStoryboardMetric];
    }
    
    // show the storyboard
    self.window.rootViewController = [storyboard instantiateInitialViewController];
    [self.window makeKeyAndVisible];
    
    return YES;
}
Here's a quick demo project: https://github.com/versluis/Pick-a-Storyboard/ Hope this helps!

John on How to load different Storyboards for different versions of iOS in Xcode 5

Saturday, 28th January 2017

Wondering if this same code can be edited to allow the user to save the settings (preference) of which storyboard they prefer. I have an app that uses an Imperial Storyboard and a Metric Storyboard. At startup the user actually sees a Startup Storyboard and then they select Imperial or Metric... That works fine... I have an option to allow them to save their default unit of measure, so they don't have to select Imperial or Metric every time they start the app again using NSUserDefaults... Those defaults too save properly. My problem is, that I cannot tell in the AppDelegate file that if the user saved Imperial, how to only display the Imperial Storyboard on next entry, and of course, if the user selected Metric, how to load only that Storyboard. So while I came close to editing your sample (thank you) I am having a bit of trouble having the AppDelegate file handle the selection. If you have any advice much appreciated... Here is some sample code... (not working) no errors, just not selecting the saved Storyboard from the user preferences as every time the app starts up, it always goes to the Start Storyboard and not the Imperial or Metric Storyboard... ***Code Below *** in AppDelegate.m

- (UIStoryboard *)grabStoryboard {
    
    UIStoryboard *storyboard;
    
    // detect the user default preference unit of measure
    
    NSUserDefaults *defaultimperial = [NSUserDefaults standardUserDefaults];
    if (![defaultimperial objectForKey:@"unitSwitchImperial"]) {
        [defaultimperial setBool:YES forKey:@"unitSwitchImperial"];
        storyboard = [UIStoryboard storyboardWithName:@"iPhoneImperial" bundle:nil];
        
         NSLog(@"Imperial Measurement Storyboard");
    } else {
        
        NSUserDefaults *defaultmetric = [NSUserDefaults standardUserDefaults];
        if (![defaultmetric objectForKey:@"unitSwitchMetric"]) {
            [defaultmetric setBool:YES forKey:@"unitSwitchMetric"];
        }
        storyboard = [UIStoryboard storyboardWithName:@"start" bundle:nil];
         NSLog(@"Start Storyboard");
    }
    
    return storyboard;
}
Then in the following...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

NSUserDefaults *defaultimperial = [NSUserDefaults standardUserDefaults];
        if (![defaultimperial objectForKey:@"unitSwitchImperial"]) {
            [defaultimperial setBool:YES forKey:@"unitSwitchImperial"];
            
        }

UIStoryboard *storyboard = [self grabStoryboard];

       // show the storyboard
        self.window.rootViewController = [storyboard instantiateInitialViewController];
        [self.window makeKeyAndVisible];

*** so again, there are no errors, only that the app ALWAYS starts at the Start Storyboard, even though the user as selected the Imperial storyboard to start at the next time they enter the app... Any help much appreciated... John

Lyn on How to build a UICollectionView in iOS 8

Friday, 27th January 2017

Thank you so much for this tutorial. That one line of code was tripping me up for so long and now I can finally see my collection! Thanks again!

charlesr1971 on How to kill your app when it enters background mode

Monday, 16th January 2017

Excellent. Thanks Jay!

Jay Versluis on How to kill your app when it enters background mode

Monday, 16th January 2017

You're absolutely right, and you're in luck too, because Apple have half-implemented something like that. Here's what you can do:

  • plugin your device into your Mac (only works with real devices, not the simulator)
  • open Xcode
  • navigate to Window - Devices, then select your device
Xcode will now read the device's log file and display it (remember the log file contains every message any system service or app wants to write in there, including our own NSLog messages). As you use your device, you can see new messages displayed in real time.

charlesr1971 on How to kill your app when it enters background mode

Monday, 16th January 2017

Jay. That's a great explanation, but "where there is a will, there is a way..." Apple should be able to build this functionality into XCode, maybe as a preference.