Reset Push Notification Settings For iOS App

Answer: http://stackoverflow.com/a/4080720/4395879

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.
Update: As noted in the comments below, this solution stopped working since iOS 5.1. I would encourage filing a bug with Apple so they can update their documentation. The current solution seems to be resetting the device's content and settings.
Update: The tech note has been updated with new steps that work correctly as of iOS 7.
  1. Delete your app from the device.
  2. Turn the device off completely and turn it back on.
  3. Go to Settings > General > Date & Time and set the date ahead a day or more.
  4. Turn the device off completely again and turn it back on.

How to erase bluetooth devices from Mac

Original answer -> http://apple.stackexchange.com/a/150979

In System Preferences > Bluetooth, make sure that Bluetooth is on and the Show Bluetooth in menu bar check box is checked. Then hold down alt or option before clicking the Bluetooth toolbar menu icon. Now, in the device's contextual menu you can remove it.


dispatch_after in Swift

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
    print("test")
}

Editing the Hosts File in Mac OS X

  1. Launch Terminal, found in /Applications/Utilities/ or launched through Spotlight,
  2. Type the following command at the prompt:
    sudo nano /private/etc/hosts
  3. Enter the administrator password when requested,
  4. Once the hosts file is loaded within nano, use the arrow keys to navigate to the bottom of the hosts file to make your modifications,
  5. When finished, hit Control+O followed by ENTER/RETURN to save changes to /private/etc/hosts, then hit Control+X to exit out of nano,
  6. Quit out of Terminal when finished.

How to Create Local Notifications in iOS App

 - (void) setupLocalNotification:(NSString*)dateString {
   
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EEST"]];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH mm"];
    
    NSDate *itemDate = [formatter dateFromString: dateString];
    
    if ([itemDate compare:[NSDate dateWithTimeIntervalSinceNow:0.1]] == NSOrderedAscending) {
        return;
    }
    
    
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    
    
    localNotif.alertBody = @"Alert message";
// Set the action button
    localNotif.alertAction = @"View";
    
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 0;
    

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

Check iOS Version


You can get the OS version using: 
NString *systemVersion = [[UIDevice currentDevice] systemVersion];

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

Usage : 

    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {

        

    }
    else {
        
    }


source: stackoverflow.com

How to cancel a local git commit

(loosing changes, like checking out previous commit) 
 
git reset --hard HEAD~1
 
 
(will not lose changes, only cancels commit) 
git reset --soft HEAD~1

Starting Phone Calls From iPhone App

To start phone call from iPhone app, create url with phone link and open that url via ..sharedApplication] openURL: ... method.


    NSURL *phoneUrl = [NSURL URLWithString:@"tel:1-408-555-5555"];
    
    if ([[UIApplication sharedApplication] canOpenURL:phoneUrl])
        [[UIApplication sharedApplication] openURL:phoneUrl];


Apple document about phone links:
https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html

Basic Git Commands

Some Useful Git Commands

Create local git repository
git init

Add all files to git
git add .

Remove remove file from git (this command doesnt delete your file from disk)
git rm --cached <file path>

Make your first commit
git commit -a -m "<commit message>"

Changing latest commit message
git commit --amend -m "<commit message>"

Setup your remote repo
git remote add <remote name> <remote url>

Push local resources to remote repo
git push -u <remote name> <branch name>

Remove remote:
git remote rm <remote name>

Clone remote repository
git clone <url>


List branches
git branch

Create branch
git branch <branch name>

Switch branch
git checkout <branch name>

Create and switch that branch
git checkout -b <branch name>

Delete branch
git branch -d <branch name>

Delete remote branch
git push <remote name> :<branch name>
Rename branch
git branch -m <old branch name> <new bracnh name>

Add tag
git tag -a v1.0 -m <description message>

Push tag
git push <remote name> <tag name>

Push all tags
git push <remote name> --tags

Delete tag
git tag -d <tag name>

Delete remote tag
git push <remote name> :refs/tags/<tag name>

Delete All .DS_Store files in directory

.DS_Store (Desktop Services Store) is a proprietary format hidden file created by Apple Inc.'s Mac OS X operating system to store custom attributes of a folder such as the position of icons or the choice of a background image. ()


To remove all DS_Store files in a specific directory:


    • Select Applications > Utilities to launch Terminal.

    • Enter the following UNIX command:
    sudo find <directory path> -name ".DS_Store" -depth -exec rm {} \;
    • When prompted for a password enter your Mac OS X Administrator password.


    Adding ARC and non-ARC files to project

    Import non-ARC files to ARC project

    If your project is compiling with ARC, and you want to import some non-ARC file to your project:
    import non-ARC files to your project,
    click the Project -> Build Phases Tab, and expand Compile Sources section,
    select non-ARC files and double click your selection,
    Then add -fno-objc-arc to the popup window.

     

    Import ARC files to non-ARC project

    If your project is compiling with ARC, and you want to import some non-ARC file to your project:
    import ARC files to your project,
    click the Project -> Build Phases Tab, and expand Compile Sources section,
    select non-ARC files and double click your selection,
    Then add -fobjc-arc to the popup window.




    If You can't empty the Trash

    • First, try holding the Option key as you choose Empty Trash from the Finder's File menu.
    if this is not worked for you, open terminal and write 
    • sudo rm -rf <file path>
    if you don't know full file path, just write sudo rm -rf and don't press Enter yet, drag item from trash to terminal and this will automatically adds file path.


    Show / Hide Hidden Files on Mac OS X

    • To show hidden files, open terminal window and write 2 line below:
    defaults write com.apple.finder AppleShowAllFiles TRUE
    killall Finder
    • If you want them invisible again, chane TRUE flag to FALSE and killall finder
    defaults write com.apple.finder AppleShowAllFiles FALSE
    killall Finder

    Difference Between nil and NULL

    nil is the literal null value for Objective-C objects,
    NULL is the literal null value for arbitrary C pointers.

    Main difference between nil & NULL is that you can send messages to nil, so you can use it in some places where NULL can't work.

    Claer VLC Player video history from dock icon right click menu

    This is not life saving trick but i was needed that and here how it is:
    go to "/Users/<username>/Library/Preferences" folder and delete "org.videolan.vlc.LSSharedFileList.plist" file.

    NSTimer

    Define NSTimer in header file, so you can handle it if you need

    NSTimer *timer;


    // Creating a timer that call repeatJob every 1.0 sec

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(repeatJob) userInfo:nil repeats:YES];



    //killing timer

    if([timer isValid]){

    [timer invalidate];

    timer = nil;

    }



    //there is no pause and play function for NSTimer, you should kill and recreate it


    info.plist file dynamic $variables

    Bundle Display Name - ${PRODUCT_NAME}
    Executable File - ${EXECUTABLE_NAME}
    Bundle Name - ${PRODUCT_NAME}

    UIImageView Animation

    NSArray *images = [NSArray arrayWithObjects:

    [UIImage imageNamed:@"image.png"],

    [UIImage imageNamed:@"image2.png"],

    [UIImage imageNamed:@"image3.png"],

    [UIImage imageNamed:@"image4.gif"],

    nil];


    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 200)];

    imageView.animationImages = images;

    imageView.animationDuration = 1;

    imageView.animationRepeatCount = 0; // 0 = nonStop repeat

    [imageView startAnimating];


    [self.view addSubview:imageView];

    [imageView release];

    Show Local HTML Files in UIWebview

    //loading local html file into UIWebview
    NSBundle *bundle=[NSBundle mainBundle];
    NSString *filePath = [bundle pathForResource:@"index" ofType: @"html"];
    NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
    NSURLRequest *request = [NSURLRequest requestWithURL:fileUrl];
    [webview loadRequest:request];

    //you can also show .doc .ppt .xls files in UIWebview with NSURLRequest