Hello readers,

Today i am going to show, what could happen if you take a screenshot of any app content for some user. Snapchat users get notified that this user has taken a screenshot of your post.

This is what we are going to implement.

It is not that hard as it sounds, iOS 7.0 and later gives you an observer in NSNotificationCenter named UIApplicationUserDidTakeScreenshotNotification.

Just add this observer in the view did load and you can add a selector in this to perform any other task after a screenshot is taken.

Add the following code in the ViewDidLoad of you view controller.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenshotDetected) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
-(void)anotherAlert {
    UIAlertController *alertController = [UIAlertController
                                          message:@"Did you smile...???"
    UIAlertAction *okAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Lets see", @"OK action")
                               handler:^(UIAlertAction *action)
                                   NSLog(@"OK action");
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];

You can perform any selector in this, i have added an alert controller, you can get the details of the user logged in, and can perform a notification.

More in this screenshot stuff, i am currently trying to take a picture from the front camera, when a screenshot is taken.


Hello again readers, we were just thinking a new category to our blog posts, so here we bring you a post on watchOS. Yes this post will guide you through the basics of how to develop an app for the Apple watch.

This post will help you create a simple table view which will display a label and a detail Interface controller which will contain the details of the cell selected in the table view.

Simulator Screen Shot Sep 27, 2016, 10.55.44 AM

Tables basically shows the list of data whose contents changes dynamically. The class from which it inherits is WKInterfaceTable class. Note that tables on watch OS supports only single columns.

The layout should be set in the interface of the watch extension and the data to be displayed should be displayed runtime.

Screen Shot 2016-09-27 at 11.07.36 AM

MainWC is the Scene which will be displayed first as the watch app launches, I have placed a row controller and a label in it called “Country Name”, give the outlet to this label in the row controller class. This will be the custom class for you row controller. You can add one or more row controllers in the Scene as per your requirement. The row controller is a template used for displaying the content in the app at run time.

For this first we need to determine the number of rows that will be displayed in the app. The method in which we pass the number of rows is setNumberOfRows:withRowType: and we can use this to iterate over the total number and add content on each row with rowControllerAtIndex:.

This is the array I have used to insert the data.

arrWeekDay = [[NSMutableArray alloc] initWithObjects:@"Sunday",@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday", nil];

[self.weekName setNumberOfRows:arrWeekDay.count withRowType:@"city"];
NSInteger rowCount = self.weekName.numberOfRows;
// Iterate over the rows and set the label for each one.
for (NSInteger i = 0; i < rowCount ; i++) {
    // Get the to-do item data.
    NSString* itemText = arrWeekDay[i];
    // Assign the text to the row's label.
    WeekDay* row = [self.weekName rowControllerAtIndex:i];
    [row.lblName setText:itemText];

Now the part is running the watch app. Go to the target selection in Xcode and select the watch extension. Set the device as specified, iPhone 7 + Apple Watch Series 2 (this will be shown if you have xcode 8, in Xcode 7.2 iPhone 7 will not be there.) Hit the play button.

You will be shown a new simulator specially made for watch, the watch app run there.

          Simulator Screen Shot Sep 27, 2016, 10.56.50 AM          Simulator Screen Shot Sep 27, 2016, 10.56.34 AM

Now we will see what can we do if we select the row of this table,

There is a similar method as for the iOS, didSelectRowAtIndexPath for the WatchOS called didselectrowatindex. This is how you use it,

-(void)table:(WKInterfaceTable *)countryName didSelectRowAtIndex:(NSInteger)rowIndex
    NSString *data = [arrCityName objectAtIndex:rowIndex];
    [self presentControllerWithName:@"detailWC" context:data];

Here the present controller with name will present the scene and the context will send the data to the next presenting controller. We can use this data in the next controller.

Here is have passed the selected day to the next controller and displayed it through the context in the next controller in a label.

zRun it again and select any day, a new interface will be presented, with the day you selected as the label in it.
Simulator Screen Shot Sep 27, 2016, 11.56.47 AM          Simulator Screen Shot Sep 27, 2016, 11.56.42 AM

Thats all about how to display data in tables in WatchOs, for further practice try to generate different results on the select, calculations with the help of the data from frameworks. Thanks.


Hello Readers,

Lets, just recall the steps we follow when starting a new project, most of the time we unselect the Size Classes selection given just below the Auto Layout option, Today we will see what it is actually used for and see how it can be useful for our apps.

The size Classes is a new technology introduced in iOS 8, which allows users to specify width and height combinations to the design for different devices and even orientations. Prior to iOS 8 the developers had to use multiple storyboards and write code for orientation checks (Landscape / Portrait) to use different UILayout as per device / orientation. This tutorial will guide through the size classes and how to use its compact / regular heights for which devices.

Designing the view

Start by creating a new single view application, enter the details such as product name, organization name, organization identifier then select the language as swift and make sure that the devices is selected Universal. Go to the storyboard and edit the main view color to light blue and add 4 buttons, place each at one corner of the view. Name those buttons as one, two, three, four or as per their position in the view – top-left,top-right, bottom-left and bottom-right. The storyboard should look like this.Screen Shot 2015-10-27 at 11.17.47 AM

Now build and run your project in iPhone 5s simulator. You will see that the two right buttons are not visible on the screen. This is because The layout was designed with the Size class for Any-width and Any-height. Now, let’s pin the buttons to the corners.

Now make sure that the interface builder has these items selected, the Auto-Layout and the Size-Classes, as shown below.Screen Shot 2015-10-27 at 11.21.51 AM

Select the top-left button and use the right click and start dragging to the left, select the “leading space to container margin”, and do the same dragging towards the top and add the “Top space to layout guide” constraint for the button.

Add the following constraints for the other Buttons:

  • top-right button -> Trailing Space to Container Margin, Top Space to Top Layout Guide
  • bottom-left button -> Leading Space to Container Margin, Bottom Space to Bottom Layout Guide
  • bottom-right button -> Trailing Space to Container Margin, Bottom Space to Bottom Layout Guide

After this build and run the project, in iPhone and iPad check for all orientations too, the buttons will be set to their margins.

Now if you take your attention on the bottom of the screen you will see something like this, this “wAny hAny” is the default size class layout selected.

Screen Shot 2015-10-27 at 1.28.50 PM

Click on it a screen like below will open, on which when you drag your mouse pointer, different selection can be made. These are the different layout in the size classes which the Xcode offers.

Size Classes

The size classes tool presents a grid of nine tiles. When you select the size class Any for either dimension, green dots in tiles indicate areas where your base value design specifications take effect for this size combination. For example, for the Any Width | Any Height combination, green dots in all of the tiles show that the layout constraints and views that you specify on the Interface Builder canvas apply to every device size and orientation.

When you select either the compact size class or the regular size class for either dimension, any change you make to your layout for that dimension overrides the base layout specifications. For example, when you select the Compact Width | Any Height combination, the constraints that you change—and any views that you add or remove—apply only to compact width layouts, for any height.

When you select a specific size class for each dimension, a single green dot in a tile and the label Final Values indicate that your layout values apply exclusively to the shaded tiles on the grid. For example, when you select Compact Width | Regular Height, changes to layout constraints and views apply exclusively to iPhone devices in portrait orientation.

any-any           compact-any          compact-regular

The following image will show you the width and the height layout the devices use in their landscape and portrait mode.

size classes

Select the “wCompact hCompact” in the size class, you will notice that the size of the controller is reduced. this size class can be used for all iPhones except for iPhone 6 Plus.

Adding a button for Landscape orientation only

Now add a button at the top center of the view, name it “Top-Center”. Also give auto layout constraints to it, These constraints will allow the button to be placed at a fixed distance from the top and stay at the center.

  • Top Space to Top Layout Guide
  • Center Horizontally in Container

Now the Compact – Compact size class combination is for iPhone Landscape, so now we have updated the view for iPhone in the Landscape mode only. The landscape mode will have a button more than the portrait mode.

Simulator Screen Shot Oct 27, 2015, 2.19.44 PM               Simulator Screen Shot Oct 27, 2015, 2.19.49 PM

The above images are the screenshots of iPhone 4s Portrait and landscape modes.

Changing font for iPad only

Now lets see the layout which is designed for the iPad landscape and portrait mode. this can be done when you select the wRegular – hRegular on the layout menu os size classes. We are going to change the font size of the button but just for the iPad only. When we do note that the iPads use only the wRegular hRegular for both the orientations – landscape and portrait, so the change in the button size will be visible on both the orientations.

Select any one button on the view controller, and go to the right panel on the Xcode in the properties tab of the button. You will see a ‘+’ sign just left to the font selection tab.

Screen Shot 2015-10-27 at 3.19.29 PM                       Screen Shot 2015-10-27 at 3.19.38 PM

Click it, and a menu will be open which will offer you to select some options, These are the same size layout which we saw earlier, only this time we are giving them a different font for that particular size class. Select Regular Width and the Regular Height. A new font for wR hR is just below the Font tab. Now run the project in any iPhone simulator, it should not show any changes, but stop the project and run it again selecting any iPad device, you will see that the button size has changed.

Simulator Screen Shot Oct 26, 2015, 10.17.42 AM

So this was the tutorial on what size classes are and how to use them. Hope this was useful.

todaywidget-display image

Hello readers, today we’re going to see how today widget works and how to implement in our app.

1. What is an Extension and a Today Widget.

First of all what is a widget, briefly speaking a widget gives users quick access to information that’s important right now. For example, users open the today widget to check daily schedule, stock updates, or even perform a quick task such as marking an item as done. Basically users tend to open the Today view frequently, and they expect the information they’re interested in to be instantly available to them.

Now an extension is launched and controlled by a host app, lets say “safari”, or the app from which you want to display the data.

Extensions created for the today extension point, called widgets, are meant to provide simple and quick access to information which is fetched from some host app. Widgets link to the Notification Center framework. It’s important that you design your widget with a simple and focused user interface, because too much interaction can be a problem. Note one important thing that you don’t have access to a keyboard.

That’s about enough theoretical knowledge on today extensions, lets start creating one.

2. Target Setup

Step 1 : Project Setup

If you want to build this widget as an extension to an existing app, go ahead and open your Xcode project, and jump to the second step. If you’re starting from scratch just like me, then you first need to create a containing app.

Open Xcode and in the File menu select New > Project…. We will be using Objective-C as the programming language and the the Single View Application template to start with and give a name as you wish.

Screen Shot 2015-10-14 at 10.31.48 AM

Step 2 : Add New Target

Open the File menu and choose New > Target… In the Application Extension category, select the Today Extension template.

Screen Shot 2015-09-25 at 2.12.18 PM

Click next and give your widget a name based on the use it is designed for.

Now you’ll see that the Project to which the target will be added is the project we’re currently working with and the extension will be embedded in the containing application. Also note that the extension has a distinct bundle identifier based on the one of the containing application.

Screen Shot 2015-09-25 at 2.12.50 PM

Click Finish to create the new target. Xcode has created a new scheme for you and it will ask you to activate it for you. Click Activate to continue.

Screen Shot 2015-09-25 at 2.13.02 PM

You’ll see that Xcode has created a new group for the widget named multiplyTodayExample and added a number of files to it, a UIViewController subclass and a storyboard. That’s right, a widget is nothing more than a view controller and a storyboard. If you open the view controller’s header in the code editor, you’ll notice that it is indeed subclassingUIViewController. If you check the storyboard of the today widget you’ll see that a default label is already present saying “Hello World”

If you select the extension target from the list of targets, open the Build Phases tab, and expand the Link Binary With Libraries section, you’ll see that the new target is linked to the Notification Center framework.

Screen Shot 2015-10-14 at 10.50.47 AM

3. Test Run

Step 1 : Running the today widget

Just as simple as that its time to see how the widget looks. Yes its all ready, With the multiplyTodayExample scheme selected, select Run from the Product menu or hit Command-R. Reveal the notification center by swiping from the top of the screen to the bottom and tap the Edit button at the bottom of the notification center.

Screen Shot 2015-09-25 at 2.48.34 PM

Your widget should be available to add to the Today section. Add it to the Today section by tapping the add button on its left.

Screen Shot 2015-09-25 at 2.49.06 PM

This is how the widget would look in the today tab.

iOS Simulator Screen Shot Sep 25, 2015, 2.49.28 PM

4. Adding some Functionalities

Step 1 : User Interface

Now we’re going to add a text field and a button on the storyboard of the widget. Add the link the property and the action of the text field and button respectively. Add the auto layout or auto resizing to the elements on the story board.

Screen Shot 2015-10-14 at 11.29.46 AM

Step 2 : Fixing the bottom margin

Add the following code in the widget view controller.m for the realignment of the bottom margin.

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)margins
    margins.bottom = 20.0;
    return margins;

Step 3 : UIPasteBoard Methods and button action

As there is no access to the keyboard, I have kept some text on the app view controller which can be copied and used in this widget. For this i have used the UIPasteBoard form the UIKit, the code for this is as follows.

->In the app view vontroller.m
- (void) textPressed:(UILongPressGestureRecognizer *) gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateRecognized &&
        [gestureRecognizer.view isKindOfClass:[UILabel class]]) {
        //UILabel *someLabel = (UILabel *)gestureRecognizer.view;
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:_txtFirst.text];
        //let the user know you copied the text to the pasteboard and they can no paste it somewhere else


- (void) textTapped:(UITapGestureRecognizer *) gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateRecognized &&
        [gestureRecognizer.view isKindOfClass:[UILabel class]]) {
        //UILabel *someLabel = (UILabel *)gestureRecognizer.view;
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:_txtSecond.text];
        //let the user know you copied the text to the pasteboard and they can no paste it somewhere

-> In the widget view controller's view did load.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *strPaste = pasteboard.string;
if (strPaste) 
    self.txtfieldNum1.text = strPaste;

And the following code for the button action.

- (IBAction)btnAddClick:(UIButton *)sender 
    int x = [_txtfieldNum1.text intValue];
    int y = 2;
    sum = x * y;
    sum1 = [NSString stringWithFormat:@"%d", sum];
    [_txtfieldNum1 setText:sum1];
    //_txtfieldNum1.text = @"1234";

Step 4 : Build and Run

First run the widget scheme in the Today section, and then run the app scheme.

Once the app starts running, select the number from the text “0123456789”, that you wish to multiply with the help today widget.

Screen Shot 2015-10-14 at 10.11.06 AM

Now drag the top menu from where the today tab and the notifications tab are opened. You will notice that because of the use of UIPasteBoard the copied text is already in the UITextfield.

Simulator Screen Shot Oct 14, 2015, 10.11.22 AM

Then press the multiply button and the text in the textfield will get multiplied by 2.

Simulator Screen Shot Oct 14, 2015, 10.11.26 AM


Although this was very easy logic implemented here in this today widget, this should give a good idea about what today widgets and extensions are and how to use them. I hope the knowledge presented here comes in useful when building your next today widget.