Keep iPhone from sleeping

To stop your app from timing out and going to sleep you can use:
[UIApplication sharedApplication].idleTimerDisabled = YES;

This will, obviously, disable the idle timer and stop your iphone from automatically going into sleep mode.

Note: To re-enable the idle timer when you no longer need to keep the phone awake (generally after that view has been removed) using:
[UIApplication sharedApplication].idleTimerDisabled = NO;

Open URL in Browser for Windows Phone 8

using System;
using Microsoft.Phone.Tasks;

WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://msdn.microsoft.com", UriKind.Absolute);
webBrowserTask.Show();

Get Windows Phone Screen Size and Scale Factor

using System.Windows;  
public void GetScreenResolution()  
{  
     double w = Application.Current.Host.Content.ActualWidth;  
     double h = Application.Current.Host.Content.ActualHeight;  
     int scale = Application.Current.Host.Content.ScaleFactor;  
}

The following is an overview of the current characteristics of all these properties:
 WVGAHDWXGA
ActualWidth480480480
ActualHeight800853800
ScaleFactor (%)100150160
Resulting Size (Width/Height x Scale)480x800720x1280768x1280

Debug or Print Log in Windows Phone 8

System.Diagnostics.Debug.WriteLine("")

You can debug the native code in the windows phone Runtime Component by selecting the native debug engine for the UI Task. in this case you will also get the debug output.

to select the native debug engine for UI Task

1. Go to debug property page by right clicking on the project and selecting the "properties" menu followed by selecting the "Debug" tab.

2. Under the "UI Task" there is a drop down. select "Native Only"

Dismiss UIAlertViews or UIActionSheet When Enter Background State

- (void)checkViews:(NSArray *)subviews {
    Class AVClass = [UIAlertView class];
    Class ASClass = [UIActionSheet class];
    for (UIView * subview in subviews){
        if ([subview isKindOfClass:AVClass]){
            [(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
        } else if ([subview isKindOfClass:ASClass]){
            [(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
        } else {
            [self checkViews:subview.subviews];
        }
    }
}

Calling it from the applicationDidEnterBackground procedure

[self checkViews:application.windows];

Eliminate Extra separators below UITableView

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     // This will create a "invisible" footer
     return 0.01f;
 }

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{        
    return [UIView new];

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}

Create UIColor from a Hex String

// Assumes input like "#00FF00" (#RRGGBB).
+ (UIColor *)colorFromHexString:(NSString *)hexString {
    unsigned rgbValue = 0;
    NSScanner *scanner = [NSScanner scannerWithString:hexString];
    [scanner setScanLocation:1]; // bypass '#' character
    [scanner scanHexInt:&rgbValue];
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}

UIImage resize (Scale proportion)

// grab the original image
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
    
// scaling set to 2.0 makes the image 1/2 the size. 
UIImage *scaledImage = 
                [UIImage imageWithCGImage:[originalImage CGImage] 
                              scale:(originalImage.scale * 2.0)
                                 orientation:(originalImage.imageOrientation)];

Add Index to UITableViewController

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    [tempArray addObject:@"{search}"]; //search icon
    [tempArray addObject:@"#"];
    [tempArray addObject:@"A"];
    [tempArray addObject:@"B"];
    [tempArray addObject:@"C"];
    [tempArray addObject:@"D"];
    [tempArray addObject:@"E"];
    [tempArray addObject:@"F"];
    [tempArray addObject:@"G"];
    [tempArray addObject:@"H"];
    [tempArray addObject:@"I"];
    [tempArray addObject:@"J"];
    [tempArray addObject:@"K"];
    [tempArray addObject:@"L"];
    [tempArray addObject:@"M"];
    [tempArray addObject:@"N"];
    [tempArray addObject:@"O"];
    [tempArray addObject:@"P"];
    [tempArray addObject:@"Q"];
    [tempArray addObject:@"R"];
    [tempArray addObject:@"S"];
    [tempArray addObject:@"T"];
    [tempArray addObject:@"U"];
    [tempArray addObject:@"V"];
    [tempArray addObject:@"W"];
    [tempArray addObject:@"X"];
    [tempArray addObject:@"Y"];
    [tempArray addObject:@"Z"];
    return tempArray;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    NSLog(@"click %@", title);
    return 0; 
}

Play sound without disabling ipod playback

#import <AVFoundation/AVAudioSession.h>
#import <AudioToolbox/AudioToolbox.h>

// Set the AVAudio Session property
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
OSStatus propertySetError = 0;
UInt32 allowMixing = true;
propertySetError = AudioSessionSetProperty (
      kAudioSessionProperty_OverrideCategoryMixWithOthers,
      sizeof (allowMixing),
      &allowMixing
);
NSError *activationError = nil;
[session setActive:YES error:&activationError];
// Now play the sound in filePath
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSError *error;
AVAudioPlayer *player = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:&;error]autorelease];