Rectangle 27 1

/*Here goes the CSS for all screens*/

@media handheld {

    /*Here goes the CSS for mobile phones and tablets*/

}

set the viewport metatag in your html:

<meta name="viewport" content="width=device-width, height=device-height" />

Is there a way to target this in jQuery? The elements I need to resize are created dynamically, and not linked to a class.

Hm...Chrome on the desktop is responding to the "handheld" query: jsfiddle.net/WNKpj/ EDIT: Wait nevermind. My mistake.

matchMedia doesn't return a booelan, but a MediaQueryList. Use window.matchMedia("handheld").matches instead.

javascript - How to detect mobile browser for screen size? - Stack Ove...

javascript jquery mobile detect
Rectangle 27 19

You basically already have the solution, which I'm guessing you found from one of my recent answers :)

com.apple.springboard.hasBlankedScreen

There are multiple events that occur when the screen blanks, but this one should suffice:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                NULL, // observer
                                hasBlankedScreen, // callback
                                CFSTR("com.apple.springboard.hasBlankedScreen"), // event name
                                NULL, // object
                                CFNotificationSuspensionBehaviorDeliverImmediately);

where the callback is:

static void hasBlankedScreen(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
    NSString* notifyName = (__bridge NSString*)name;
    // this check should really only be necessary if you reuse this one callback method
    //  for multiple Darwin notification events
    if ([notifyName isEqualToString:@"com.apple.springboard.hasBlankedScreen"]) {
       NSLog(@"screen has either gone dark, or been turned back on!");
    }
}

Update: as @VictorRonin said in his comment below, it should be easy to keep track yourself whether the screen is currently on or off. That allows you to determine whether the hasBlankedScreen event is occurring when the screen goes on or off. For example, when your app starts, set a variable to indicate that the screen is on. Also, any time any UI interaction occurs (button pressed, etc.), you know the screen must currently be on. So, the next hasBlankedScreen you get should indicate that the screen is off.

Also, I want to make sure we're clear on the terminology. The device locks when the screen automatically darkens due to a timeout, or when the user manually presses the power button. This happens regardless of whether the user has a Passcode configured. At that time, you will see the com.apple.springboard.hasBlankedScreen and the com.apple.springboard.lockcomplete events.

When the screen turns back on, you will see com.apple.springboard.hasBlankedScreen once again. But, you will not see com.apple.springboard.lockstate until the user has actually unlocked the device with a swipe (and maybe a passcode).

There's yet another way to do this. You can use an alternate set of APIs to listen for this notification, and also get a state variable when the notification comes:

#import <notify.h>

int status = notify_register_dispatch("com.apple.springboard.hasBlankedScreen",
                                      &notifyToken,
                                      dispatch_get_main_queue(), ^(int t) {
                                          uint64_t state;
                                          int result = notify_get_state(notifyToken, &state);
                                          NSLog(@"lock state change = %llu", state);
                                          if (result != NOTIFY_STATUS_OK) {
                                              NSLog(@"notify_get_state() not returning NOTIFY_STATUS_OK");
                                          }
                                      });
if (status != NOTIFY_STATUS_OK) {
    NSLog(@"notify_register_dispatch() not returning NOTIFY_STATUS_OK");
}

and you will need to keep an ivar, or some other persistent variable, to store the notification token (do not just make this a local variable in the method that registers!)

int notifyToken;

You should see the state variable, obtained via notify_get_state(), toggle between 0 and 1, which will let you distinguish between screen on and off events.

Although this document is very old, it does list which notification events have an associated state that can be retrieved via notify_get_state().

I have already tried this, turns out, this notification comes in both the scenarios, when device goes to sleep and when device awakes from the sleep.: Jan 16 18:48:53 unknown SpringBoard[15] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0 Jan 16 18:48:53 unknown Myapp[1921] <Warning>: Darwin notification NAME = com.apple.springboard.hasBlankedScreen an 16 18:50:29 unknown SpringBoard[15] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=1 Jan 16 18:50:29 unknown Myapp[1921] <Warning>: Darwin notification NAME = com.apple.springboard.hasBlankedScreen

You can keep a state variable, whether a device is asleep now or awake.

Do I notice correctly that my app will not receive lockstate or lockcomplete notifications if it is already in the background when the lock action occurs?

@SpencerWilliams, not necessarily. If you just press Home to background your app, assuming your app .plist does not specify that it exits on suspend, then you will get the notifications. Now, as with anything, there are limits on how much time your app gets in the background, so you may have to fiddle with things if you want to get these notifications indefinitely. That's really another question, and depends on whether we're talking about a jailbreak app or not. But, fundamentally, Darwin notifications don't stop just because you've entered the background.

@SpencerWilliams, also take careful note of the last parameter I pass when I register for the notifications. If you aren't using CFNotificationSuspensionBehaviorDeliverImmediately, then you very well might not see notifications when your app is in the background.

iphone privateapi - Is there a away to detect the event when iOS devic...

ios iphone-privateapi sleep-mode
Rectangle 27 2

You should use the takePicutre method and then detect any touches on the screen.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    self.imgPicker.takePicture;
}

cocoa touch - iPhone SDK - How to take a picture with custom camera vi...

iphone cocoa-touch camera iphone-sdk-3.1.3
Rectangle 27 6

Since this is for an enterprise app, perhaps you could put a transparent overlay view atop everything, that in a drawRect went opaque when it detected the layer was being asked to render for a screen shot (perhaps by looking back up the stack trace?)

You might try setting debug points in every possible view and layer drawing methods, and see if anything is triggered by a screenshot.

drawRect wasn't triggered by screenshot, but that was a good idea.

Disabling iPhone screenshot feature - Stack Overflow

iphone screenshot
Rectangle 27 6

Since this is for an enterprise app, perhaps you could put a transparent overlay view atop everything, that in a drawRect went opaque when it detected the layer was being asked to render for a screen shot (perhaps by looking back up the stack trace?)

You might try setting debug points in every possible view and layer drawing methods, and see if anything is triggered by a screenshot.

drawRect wasn't triggered by screenshot, but that was a good idea.

Disabling iPhone screenshot feature - Stack Overflow

iphone screenshot
Rectangle 27 6

As mentioned by Ian MacDonald, using hitTest:: is a great solution to detect user interaction on an app wide scale, including when buttons, textfields, etc, are selected.

My solution was to subclass UIWindow and implement the hitTest method.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

   // do your stuff here

   // return nil if you want to prevent interaction with UI elements
   return [super hitTest:point withEvent:event];
}

ios - Detecting a touch anywhere on the screen - Stack Overflow

ios objective-c cocoa-touch uigesturerecognizer uiresponder
Rectangle 27 1

With the following function detect whether mobile or tablel. Then I think the best way to detect if a table is by the pixels of the screen. Example> = 800x600 is tablet.

function isMobile(){  
        var a = navigator.userAgent||navigator.vendor||window.opera;
        return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4));
        };

iphone - jQuery automatically detect mobile device and redirect to mob...

jquery iphone html css jquery-mobile
Rectangle 27 1

With the following function detect whether mobile or tablel. Then I think the best way to detect if a table is by the pixels of the screen. Example> = 800x600 is tablet.

function isMobile(){  
        var a = navigator.userAgent||navigator.vendor||window.opera;
        return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4));
        };

iphone - jQuery automatically detect mobile device and redirect to mob...

jquery iphone html css jquery-mobile
Rectangle 27 320

CGRect screenBounds = [[UIScreen mainScreen] bounds];

That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.

CGFloat screenScale = [[UIScreen mainScreen] scale];

This will give you the scale of the screen. For all devices that do not have Retina Displays this will return a 1.0f, while Retina Display devices will give a 2.0f and the iPhone 6 Plus (Retina HD) will give a 3.0f.

Now if you want to get the pixel width & height of the iOS device screen you just need to do one simple thing.

CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

By multiplying by the screen's scale you get the actual pixel resolution.

A good read on the difference between points and pixels in iOS can be read here.

Except that this isn't quite the 'actual pixel' resolution in the case of iPhone 6 Plus. It's the resolution everything is rendered at (except OpenGL) in code, with a 3x scale, but then that is down-sampled internally to the screen's native resolution of 1080 x 1920. One of many good explanations at link

Sadly, this won't give you the "true" dimensions of elements on screen, since Apple's notions of "points" and "scale" are only an approximation. (See specs on iPhone vs iPad vs iPad mini.) Presumably to reduce the number of different combinations that exist. I think iPhone 6 Plus is particularly far off.

Actually 6+ not too far off: height 736 pts / 160 (pt/in) = 4.60" logical height; actual screen height is 4.79"; 5% error. iPad is much farther off: height 1024 pts / 160 (pt/in) = 6.40" logical height; actual screen height is 7.76"; 20% error. iPad mini is OK; it matches original iPhone density. For most purposes, this means one should test iPad software on iPad mini (to make sure it is useable), then simply ignore the fact that most iPads magnify the image by 20% (compared to iPhone or iPad mini).

@Crashalot not sure what you mean by 'solve this'? It depends on the purpose you have in mind when you obtain screen resolution. As far as programmers are concerned, Jman012's answer is correct and you render into a 1242x2208 or 2208x1242 space. Heck, that's even the resolution we provide launch images at. The fact that the hardware then down samples this image and displays it on a physical screen with a smaller pixel count would be an 'implementation detail' our code shouldn't even be aware of.

ios - in iPhone App How to detect the screen resolution of the device ...

ios objective-c cocoa-touch
Rectangle 27 3

UITapGestureRecognizer
[[UIApplication sharedApplication] keyWindow]
UIView

Is there a particular task you are hoping to accomplish? There may be a better way than assigning an "anywhere" gesture.

@interface PassthroughView : UIView
@property (readonly) id target;
@property (readonly) SEL selector;
@end
@implementation PassthroughView
- (void)setTarget:(id)target selector:(SEL)selector {
  _target = target;
  _selector = selector;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  [_target performSelector:_selector];
  return nil;
}
@end


@implementation YourUIViewController {
  PassthroughView *anytouchView;
}
- (void)viewDidLoad {
  // Add this at the end so it's above all other views.
  anytouchView = [[PassthroughView alloc] initWithFrame:self.view.bounds];
  [anytouchView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
  [anytouchView setTarget:self selector:@selector(undim)];
  [anytouchView setHidden:YES];
  [self.view addSubview:anytouchView];
}
- (void)undim {
  [anytouchView setHidden:YES];
}
- (void)dim {
  [anytouchView setHidden:NO];
}
@end

[[UIApplication sharedApplication] keyWindow] does not function with buttons

hitTest:

Thanks, this works, But will need to look into the other question, as it looks like it may fit better with my solution

ios - Detecting a touch anywhere on the screen - Stack Overflow

ios objective-c cocoa-touch uigesturerecognizer uiresponder
Rectangle 27 16

if  ( ($(document).height() - $(window).height()) - $(window).scrollTop() < 1000 ){
    //do stuff
}

You can change the value "1000" to whatever you want, to trigger your script when you are that many pixels away from the bottom.

javascript - How do you detect when you're near the bottom of the scre...

javascript jquery html css
Rectangle 27 14

if  ( ($(document).height() - $(window).height()) - $(window).scrollTop() < 1000 ){
    //do stuff
}

You can change the value "1000" to whatever you want, to trigger your script when you are that many pixels away from the bottom.

javascript - How do you detect when you're near the bottom of the scre...

javascript jquery html css
Rectangle 27 2

The reason I am working on this is that my app needs to stay active and the screen cannot be locked (so I have disabled screen locking). To avoid excessive use of power, I need to dim the screen, but then return the brightness back to the original level once the app is touched.

Since you are controlling the screen brightness, you can add one transparent view controller before dimming screen on top of your root controller which does only one job, listen to tap using Tap gesture. And on tap you can dismiss the view controller and adjust brightness to previous state.

By doing so you dont have to worry about buttons being clicked as they will be below the transparent view controller. Since its a whole new view controller sitting on top of stack you dont have to modify your existing code as well.

But will this not mean that this transparent view block access to the buttons and other features?

@Remixed123 Its a new view controller on top, so it would receive all the touches on the screen.

ios - Detecting a touch anywhere on the screen - Stack Overflow

ios objective-c cocoa-touch uigesturerecognizer uiresponder
Rectangle 27 14

$(window).scroll(function(){
    if ($(window).scrollTop() == $(document).height()-$(window).height()){
        alert("We're at the bottom of the page!!");
    }
});

"It's a very, very, bad idea to attach handlers to the window scroll event. Depending upon the browser the scroll event can fire a lot and putting code in the scroll callback will slow down any attempts to scroll the page (not a good idea)", cf. Learning from Twitter

Why duplicate a selector thrice? And why use jQuery to get information that's just as easily discernible with plain ol' vanilla JS? Using window.scrollY and window.innerHeight instead of their jQuery counterparts would solve both issues.

window.scrollY
document.documentElement.scrollTop

javascript - How do you detect when you're near the bottom of the scre...

javascript jquery html css
Rectangle 27 14

$(window).scroll(function(){
    if ($(window).scrollTop() == $(document).height()-$(window).height()){
        alert("We're at the bottom of the page!!");
    }
});

"It's a very, very, bad idea to attach handlers to the window scroll event. Depending upon the browser the scroll event can fire a lot and putting code in the scroll callback will slow down any attempts to scroll the page (not a good idea)", cf. Learning from Twitter

Why duplicate a selector thrice? And why use jQuery to get information that's just as easily discernible with plain ol' vanilla JS? Using window.scrollY and window.innerHeight instead of their jQuery counterparts would solve both issues.

window.scrollY
document.documentElement.scrollTop

javascript - How do you detect when you're near the bottom of the scre...

javascript jquery html css
Rectangle 27 1

You can also subscribe for a notification: "com.apple.springboard.lockstate" and use API SBGetScreenLockStatus to determine status whether device is locked or not.

How to call and use it? actually I only want to detect the event when the screen blackens i.e. screen transitions from on/off. Thanks in advance.

Info: Its not for a jailbroken device.

First notification is used with the same code, which Nate wrote. SBGetScreenLockStatus is described in linked article. These events I added as an answer for "Device gets locked/unlocked". And it works on non jailbroken device.

iphone privateapi - Is there a away to detect the event when iOS devic...

ios iphone-privateapi sleep-mode
Rectangle 27 8

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    //----------------HERE WE SETUP FOR IPHONE 4/4s/iPod----------------------

    if(iOSDeviceScreenSize.height == 480){          

        UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];

        // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        // Set the initial view controller to be the root view controller of the window object
        self.window.rootViewController  = initialViewController;

        // Set the window object to be the key window and show it
        [self.window makeKeyAndVisible];

        iphone=@"4";

        NSLog(@"iPhone 4: %f", iOSDeviceScreenSize.height);

    }

    //----------------HERE WE SETUP FOR IPHONE 5----------------------

    if(iOSDeviceScreenSize.height == 568){

        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
        UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];

        // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        // Set the initial view controller to be the root view controller of the window object
        self.window.rootViewController  = initialViewController;

        // Set the window object to be the key window and show it
        [self.window makeKeyAndVisible];

         NSLog(@"iPhone 5: %f", iOSDeviceScreenSize.height);
        iphone=@"5";
    }

} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // NSLog(@"wqweqe");
    storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];

}

 return YES;
 }

ios - in iPhone App How to detect the screen resolution of the device ...

ios objective-c cocoa-touch
Rectangle 27 1

Ok I have had a similar problem before.

overridden the touch to handle from subclasses

identify the control that is been touched

#import <QuartzCore/QuartzCore.h>

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setMultipleTouchEnabled:YES];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    // Enumerate over all the touches 
    [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        // Get a single touch and it's location
        UITouch *touch = obj;
        CGPoint touchPoint = [touch locationInView:self.view];
        ...
    }];
}

disable the locking of screen

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

dim or increase the screen brightness

[[UIScreen mainScreen] setBrightness:0.0f]; //and
[[UIScreen mainScreen] setBrightness:1.0f];

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event does not get triggered when a button is pressed. Am I missing something?

I hope you are not forgetting the concept of passing event through responder chain. [self.nextResponder touchesBegan:touches withEvent:event];

Also since the [NSWindow makeFirstResponder:] is a window method, it only make sense after youve added the corresponding view to the window.

Pressing a button never enters -(void)touchesBegan: so I do not get the chance to pass the event through responder chain. It does enter when I press on views.

Can you add a log in the subclassed UIWindow - (void)sendEvent:(UIEvent *)event { }. To verify the reception of touch event.

ios - Detecting a touch anywhere on the screen - Stack Overflow

ios objective-c cocoa-touch uigesturerecognizer uiresponder
Rectangle 27 3

Don't use the screen size for this, it's better to use the hardware model. We are getting more and more screen sizes every year, the less you hard-code screen dimensions in your code the better for your future self.

You need a helper function to get the machine name. I'm using dispatch_once to avoid querying the system multiple times for data that won't change.

NSString* machineName()
{
    static NSString* name = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        struct utsname systemInfo;
        uname(&systemInfo);
        name = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    });
    return name;
}

Then define a few macros as needed:

#define IS_IPHONE_6      [machineName() isEqualToString:@"iPhone7,2"]
#define IS_IPHONE_6_PLUS [machineName() isEqualToString:@"iPhone7,1"]
#define IS_IPHONE_5s     [machineName() hasPrefix:@"iPhone6,"]

Finally, use the macros in your code:

if (IS_IPHONE_6) {
// for the 6
}

Note: This answer your question (detect models with macros) but you're doing it wrong IMHO. You should use autolayout and size classes, unless you support really old iOS versions...

ios - Detecting iPhone6 & iPhone6 Plus using macros - Stack Overflow

ios iphone macros ios8 device
Rectangle 27 3

Don't use the screen size for this, it's better to use the hardware model. We are getting more and more screen sizes every year, the less you hard-code screen dimensions in your code the better for your future self.

You need a helper function to get the machine name. I'm using dispatch_once to avoid querying the system multiple times for data that won't change.

NSString* machineName()
{
    static NSString* name = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        struct utsname systemInfo;
        uname(&systemInfo);
        name = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    });
    return name;
}

Then define a few macros as needed:

#define IS_IPHONE_6      [machineName() isEqualToString:@"iPhone7,2"]
#define IS_IPHONE_6_PLUS [machineName() isEqualToString:@"iPhone7,1"]
#define IS_IPHONE_5s     [machineName() hasPrefix:@"iPhone6,"]

Finally, use the macros in your code:

if (IS_IPHONE_6) {
// for the 6
}

Note: This answer your question (detect models with macros) but you're doing it wrong IMHO. You should use autolayout and size classes, unless you support really old iOS versions...

ios - Detecting iPhone6 & iPhone6 Plus using macros - Stack Overflow

ios iphone macros ios8 device