Recent Comments

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

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.

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

Monday, 16th January 2017

Hi Charles, I guess that's expected behaviour. Terminating the app from within the app is like stopping it in Xcode, which means the connection between Xcode and the running app is broken. When you relaunch the app from the device, Xcode does not know about it and hence there's no communication between the device and Xcode. The log output is still written to the device though, it's just not displayed dynamically in Xcode.

Charles Robertson on How to kill your app when it enters background mode

Monday, 16th January 2017

Great tip Jay, but here is a more difficult issue that you may be able to resolve. How do I restore NSLog to console after applicationWillTerminate is called in the simulator. Try it and you will see that NSLog stops displaying to console in XCode, once you have terminated the app & relaunched. Any ideas?

haik on How to use Swift classes in Objective-C

Saturday, 31st December 2016

Awesome, thanks a lot !

Cristian on Xcode crashes every time you open it – and how to fix it

Friday, 16th December 2016

Thaks! it's works for me!

Nikita Sahu on Xcode crashes every time you open it – and how to fix it

Thursday, 15th December 2016

Thanks man you saved me.

Jason Harrison on Xcode crashes every time you open it – and how to fix it

Tuesday, 29th November 2016

THANK YOU

Jay Versluis on How to play videos in iOS 9

Wednesday, 23rd November 2016

I know it's been a while, but I've finally found a way on how to react to the end of the video. It's a notification we can make use of, called name: AVPlayerItemDidPlayToEndTimeNotification.

// register notificaton for end of movie
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(repeatVideo:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.playerView.player.currentItem];
Once registered, add a method and do whatever you like, for example start playing the same video again:
- (void)repeatVideo:(NSNotification *)notification {
    
    // react by setting the video back to 0

    [self.playerView.player seekToTime:kCMTimeZero];
    
    // then play it again
    [self.playerView.player play];
}
Or do anything else you need, for example make your view small again. The notification does contain the player object. We can even do the whole thing as a (totally unreadable) block, in which code can be defined in the notification registration. For completion:
// register notification using a block

[[NSNotificationCenter defaultCenter]addObserverForName:AVPlayerItemDidPlayToEndTimeNotification object:self.playerView.player queue:nil usingBlock:^(NSNotification * _Nonnull note) {
    
    // your "end of video" code goes here
    [self.playerView.player seekToTime:kCMTimeZero];
    [self.playerView.player play];
}];
Hope this helps!

Rp on How to control the Preview Screenshot in the iOS Multitasking Switcher

Wednesday, 16th November 2016

Is this working on iOS 10.1.1 ? I downloaded the git project and tried to run on iPhone 6plus with iOS 10.1.1. I start the app and do the app switching and I see the content.

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

Tuesday, 8th November 2016

Super.... Works with Xcode 8 as well...

Jay Versluis on Creating an In-App Purchase in iOS 7 and Xcode 5.1

Monday, 7th November 2016

Hi Devan, I've just checked your code in my demo app (at the bottom of the article), and I'm not getting the problem. The only thing I've changed is the count variable (NSUInteger instead of int, because Xcode was throwing a warning there). Perhaps something is wrong with your product identifier?

SKProduct *validProduct = nil;
    NSUInteger count = response.products.count;
    if(count > 0){
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"Products Available!");
        // works for me
    }
    else if(!validProduct){
        NSLog(@"No products available");
        // not called when there's at least one valid product
There's also a written article about how to do this here, perhaps it helps: http://pinkstone.co.uk/how-to-create-a-single-in-app-purchase-in-ios-7/

devanrajuios on Creating an In-App Purchase in iOS 7 and Xcode 5.1

Monday, 7th November 2016

Hi jay, A very good tutorial, but i can't able to get the product from the iTunes connect. didReceiveResponse delegate method is calling but the response is i don't have the products. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ SKProduct *validProduct = nil; int count = [response.products count]; if(count > 0){ validProduct = [response.products objectAtIndex:0]; NSLog(@"Products Available!"); [self purchase:validProduct]; } else if(!validProduct){ NSLog(@"No products available"); //this is called if your product id is not valid, this shouldn't be called unless that happens. } } Can u please suggest me what are the possible errors Thanks in Advance Devan Raju

Meg on How to play videos in iOS 9

Thursday, 3rd November 2016

I'm greatful for this; works great! One question: I've set the controller view to controller.view.frame = CGRectMake(0,25, 750, 422); so you can switch from little screen to full screen. Works great. But when watching in full screen I want the view to jump back to little view when done, without having to press 'Done'. Anyone??

Jay Versluis on How to create Popovers in iOS 9

Tuesday, 1st November 2016

Awesome - thanks for sharing, Alex!

Alex Petuschak on How to create Popovers in iOS 9

Tuesday, 1st November 2016

For anyone interested, here's the working Swift version of this project, converted using Swiftify (https://objectivec2swift.com/) - https://github.com/alex-swiftify/Popovers-2015

Tema on Where is the Documents Directory for the iOS 8 Simulator

Thursday, 20th October 2016

Just use SimSim: https://github.com/dsmelov/simsim

nishad arora on How to avoid “whose view is not in the window hierarchy” error when presenting a UIViewController

Wednesday, 12th October 2016

thank you soo much that saved my day

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

Tuesday, 11th October 2016

Works with Xcode 8

Luciano Lima on How to create Popovers in iOS 9

Wednesday, 5th October 2016

Hi Jay. Great Post! I'm trying use popoverPresentationController with UIDatePicker but the datepicker don't show. You have any tip to use datepicker with popoverPresentationController?

Cam on How to take a screeshot in iOS programmatically

Sunday, 25th September 2016

Do these methods still work for ios 10?

Andy G on How to switch root view controllers in Swift

Thursday, 15th September 2016

No longer works on iOS10

Wee7ee on 3D Touch in iOS 9, Part 4: Adding Static Shortcut Items

Tuesday, 13th September 2016

Thank you very much. This works:)

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

Monday, 12th September 2016

I'm glad it helped! Yes I was confused by the documentation as well...

Jay Versluis on 3D Touch in iOS 9, Part 4: Adding Static Shortcut Items

Monday, 12th September 2016

Hi wee7ee, in that case, instantiate the tab bar controller first, then tell it which tab you'd like selected. Next, grab your nav controller and push your chosen view controller onto the nav stack. Here's what it looks like in code:

// grab our storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

// instantiate tab bar controller
UITabBarController *tab = [storyboard instantiateViewControllerWithIdentifier:@"Tab"];

// tell tab bar which tab to make visible
[tab setSelectedIndex:1];

// push second view controller onto the nav stack
UINavigationController *nav = [tab.viewControllers objectAtIndex:1];
UIViewController *view2 = [storyboard instantiateViewControllerWithIdentifier:@"View2.2"];
[nav pushViewController:view2 animated:NO];

// and make it visible
self.window.rootViewController = tab;
[self.window makeKeyAndVisible];
Note that tabs begin with 0 on the left. So in this example, we're selecting the second tab (index 1), onto which the second view controller appears in place on the navigation stack. Hope this helps :-)

Priya on How to use Swift classes in Objective-C

Monday, 12th September 2016

I have read apple's doc and stackoverflow answers. But, your tutorial helped. Thanks a lot!!! Priya

we7ee on 3D Touch in iOS 9, Part 4: Adding Static Shortcut Items

Sunday, 11th September 2016

Hi thank you for this tutorial its really good. Do you know how I have to call my view (like your DeepLink2 view) when my UINavigationController is inside a UITabBarController? UITabBarController->UINavigationBarControler->DeepLink1-> DeepLink2

hashem hashemi on How to share things with a UIActivityViewController

Saturday, 10th September 2016

Well presented. One thing I'm a problem with is sharing UIImages through email on the iPad. Everything else works fine. But specifically sharing over email on an iPad makes it just return with "completed" set to NO as soon as user taps the Mail icon. Very strange that I can't seem to find any mention off it by anyone else.

Jay Versluis on How to fix "this class is not key value coding-compliant" after accidentally adding an IBOutlet instead of an IBAction

Wednesday, 7th September 2016

Hi Yash, those things are tricky to find. It may be something in your storyboard rather than your code. Have you tried setting an exception breakpoint? Those will sometimes stop your app at the line of code that's upsetting Xcode. That's all I can suggest.