Skip to content

Instantly share code, notes, and snippets.

@Kjuly
Kjuly / ky_xcode_runscript_for_version.sh
Created Feb 22, 2015
Xcode run script for version, whenever build a new version, can choose to increase bundle version, update build date & git latest commit hash.
View ky_xcode_runscript_for_version.sh
#!/bin/bash
#
# Xcode run script for version, whenever build a new version,
# can choose to increase bundle version, update build date
# & git latest commit hash.
#
#
# Usage:
#
# Copy this file under the root folder of the project, and make sure it's executable:
@Kjuly
Kjuly / ky_registering_for_remote_notifications.md
Last active Jun 22, 2016
Registering for Remote Notifications (APN)
View ky_registering_for_remote_notifications.md

Client side:

An app must register with Apple Push Notification service (APNs) to receive remote notifications sent by the app’s push provider. In iOS 8 and later, registration has four stages:

  1. Register the notification types your app supports using registerUserNotificationSettings:.
  2. Register to receive push notifications via APNs by calling your app’s registerForRemoteNotifications method.
  3. Store the device token returned to the app delegate by the server for a successful registration, or handle registration failure gracefully.
  4. Forward the device token to the app’s push provider.

Server side:

@Kjuly
Kjuly / ky_iOS_external_keyboard_action.m
Last active Aug 29, 2015
iOS external keyboard action, like RETURN button of the external keyboard, code sample below
View ky_iOS_external_keyboard_action.m
- (NSArray *)keyCommands
{
return @[[UIKeyCommand keyCommandWithInput:@"\r"
modifierFlags:0
action:@selector(didPressExternalKeyboardReturnButton)]];
}
- (void)didPressExternalKeyboardReturnButton
{
// do ur action here
@Kjuly
Kjuly / ky_iOS_arc_variable_qualifiers.md
Last active Aug 29, 2015
iOS ARC Variable Qualifiers
View ky_iOS_arc_variable_qualifiers.md

Variable Qualifiers

You use the following lifetime qualifiers for variables just like you would, say, const.

__strong
__weak
__unsafe_unretained
__autoreleasing

  • __strong is the default. An object remains “alive” as long as there is a strong pointer to it.
@Kjuly
Kjuly / .gitignore_for_xcodeproj
Last active Aug 29, 2015 — forked from adamgit/.gitignore
Git .gitignore file for Xcode project.
View .gitignore_for_xcodeproj
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@Kjuly
Kjuly / ky_type_of_image_data.m
Created May 28, 2014
A simple function from Nolan O'Brien that can be used to determine the type of image data based on the first couple bytes of the header.
View ky_type_of_image_data.m
static inline NSPUIImageType NSPUIImageTypeFromData(NSData *imageData)
{
if (imageData.length > 4) {
const unsigned char * bytes = [imageData bytes];
if (bytes[0] == 0xff &&
bytes[1] == 0xd8 &&
bytes[2] == 0xff)
{
return NSPUIImageType_JPEG;
@Kjuly
Kjuly / ky_xcode_arm_architectures.md
Last active Aug 29, 2015
Xcode ARM Architectures
View ky_xcode_arm_architectures.md
  • ARMv8/ARM64: iPhone 6, iPhone 5s, iPad Air, Retina iPad Mini
  • ARMv7s: iPhone 5, iPhone 5c, iPad 4
  • ARMv7: iPhone 3GS, iPhone 4, iPhone 4S, iPod 3G/4G/5G, iPad, iPad 2, iPad 3, iPad Mini
  • ARMv6: iPhone, iPhone 3G, iPod 1G/2G
@Kjuly
Kjuly / ky_uiimage_rotation.m
Created Feb 13, 2014
Rotate UIImage instance (90 degree as an e.g. here).
View ky_uiimage_rotation.m
UIImage * image = ...
// Redraw image with rotation
CGSize originalSize = image.size;
CGSize finalSize = CGSizeMake(originalSize.height, originalSize.width);
UIGraphicsBeginImageContext(finalSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformIdentity;
@Kjuly
Kjuly / remove_all_viewdidunload_snippets_from_your_projects_vcs.md
Last active Dec 24, 2015
The method -viewDidUnload is deprecated in iOS 6.0. Here offers a way to remove all -viewDidUnload snippets from your project's view controllers in batch.
View remove_all_viewdidunload_snippets_from_your_projects_vcs.md

Remove All -viewDidUnload Snippets From Your Project's VCs

As Apple's Official Doc said:

-viewDidUnload is deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.

Meanwhile, it's better to remove all -viewDidUnload implements from projects that the deployment target is iOS 6.0 or later. But removing it one by one is boring, especially you've hundreds of controllers & several projects.

So, is there any script or command can do this batch job?

@Kjuly
Kjuly / ky_ignoring_just_one_deprecated_warning.m
Last active Dec 23, 2015
Ignore just one deprecated warning. e.g.: calling UIDevice's |-uniqueIdentifier| without warning.
View ky_ignoring_just_one_deprecated_warning.m
/*
Disable deprecated-declarations warning.
See http://clang.llvm.org/docs/UsersManual.html#diagnostics_pragmas
Basic workflow:
1. push current warnings onto stack
2. ignore warning we know will get thrown
3. do dodgy thing that causes warning
4. pop warnings - go back to what we had before we started fiddling with them
You can’t perform that action at this time.