Sunday, September 6, 2015

iOS : Script for creating debug and release build folder

# START script for debugLib,releaselib device and simulator

LIB_TARGET_NAME="project-name"

if [ "${ACTION}" = "clean" ]
then
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphoneos clean
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphonesimulator clean
fi

if [ "${ACTION}" = "build" ]
then
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphoneos
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphonesimulator

ARM_FILES="${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${LIB_TARGET_NAME}.a"
ARM_FILES1="${BUILD_DIR}/Debug-iphoneos/lib${LIB_TARGET_NAME}.a"
I386_FILES="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${LIB_TARGET_NAME}.a"

UNIVERSAL_OUTPUTFOLDER=${PROJECT_DIR}/build/${CONFIGURATION}-ProjectName

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
echo "Creating library..."
if [ "${CONFIGURATION}" = "Release" ]
then
lipo -create "$ARM_FILES" -output "${UNIVERSAL_OUTPUTFOLDER}/lib${LIB_TARGET_NAME}${CONFIGURATION}.a"
else
lipo -create "$ARM_FILES1" "$I386_FILES" -output "${UNIVERSAL_OUTPUTFOLDER}/lib${LIB_TARGET_NAME}${CONFIGURATION}.a"
fi
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
rm -rf "${PROJECT_DIR}/build/${CONFIGURATION}-iphoneos"
rm -rf "${PROJECT_DIR}/build/lib${LIB_TARGET_NAME}.build"
rm -rf "${PROJECT_DIR}/build/${CONFIGURATION}-iphonesimulator"
fi


# END script for debugLib,releaselib device and simulator

Create local notification in iOS

LocalNotification.h file :


#import <Foundation/Foundation.h>

@interface LocalNotification : NSObject

+ (LocalNotification*)standardLocalNotification;

- (void)scheduleAlert:(NSString*)alertBody;

- (void)scheduleAlert:(NSString*)alertBody fireDate:(NSDate*)fireDate;


@end

LocalNotification.m file :


#import <UIKit/UIKit.h>
#import "LocalNotification.h"

static LocalNotification*   localNotification = nil;

@interface LocalNotification(){
    UIApplication* application;
}

@end

@implementation LocalNotification

- (void)dealloc{
    [super dealloc];
}

- (instancetype)init{
    self = [super init];
    if (self) {
        application = [UIApplication sharedApplication];
    }
    return self;
}

+ (LocalNotification*)standardLocalNotification {

    @synchronized(self) {
        if(nil == localNotification) {
            localNotification = [LocalNotification alloc];
        }
    }
    return localNotification;
}

- (void)scheduleAlert:(NSString*)alertBody {

    [self scheduleAlert:alertBody fireDate:[[NSDate date] dateByAddingTimeInterval:1]];
}

- (void)scheduleAlert:(NSString*)alertBody fireDate:(NSDate*)fireDate{

    UILocalNotification* localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = fireDate;
    localNotification.timeZone = [NSTimeZone systemTimeZone];
    localNotification.repeatInterval = 0;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.alertBody = alertBody;

    [application scheduleLocalNotification:localNotification];
    [localNotification release];
}

@end