Search This Blog

Saturday 23 January 2016

How to Disable Application Transport Security

You just have to add NSAllowsArbitraryLoads boolean YES in
NSAppTransportSecurity dictionary



Monday 9 November 2015

How to use Protocol Delegate in iOS using Swift language

Define Protocol

There are two controllers:
FirstViewController
SecondViewController

I need to notify FirstViewController that SecondViewController ViewDidAppearCalled



import UIKit

//Define Your protocole here after Import

protocol SecondViewControllerDelegate{
      
    //Add a new function
    func SecondViewDidLoadFinished(controller:SecondViewController)

}



class SecondViewController: UIViewController {
   
    
    var delegate:SecondViewControllerDelegate?

    override func viewDidLoad() {
        super.viewDidLoad()

    }

override func viewDidAppear(animated: Bool) {
        
        if let delegate = self.delegate{
            delegate.SecondViewDidLoadFinished(self)
        }
    }




First view

import UIKit



class FirstViewController: UIViewController,SecondViewControllerDelegate {

    
    override func viewDidLoad() {
        super.viewDidLoad()

    }


@IBAction func buttonTapped(sender:UIButton){
        
        let mapObject:SecondViewControllerSecondViewController()
        mapObject.delegate = self
        self.navigationController?.pushViewController(mapObject, animated: true)   
    }

func SecondViewDidLoadFinished(controller: SecondViewController) {

//Here you will be notified that second view viewDid appear loaded
        
    }


Wednesday 21 October 2015

iOS 9 issue: The app could not be loaded because the app transport security policy requires the use of secure connection.


I have solved it with adding some key in info.plist. The steps I followed are:

Opened my Projects info.plist file

Added a Key called NSAppTransportSecurity as a Dictionary.

Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES as like following image.




Tuesday 29 September 2015

iOS Generate Random string

+(NSString *) generateRandomString
{
    NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    int len = 8;
    NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
    
    for (int i=0; i<len; i++) {
        [randomString appendFormat: @"%C", [letters characterAtIndex: arc4random_uniform([letters length])]];
    }
    
    return randomString;

}

Get iPhone application for portfolio or profile

Get iPhone application for your professional profile
Check my iPhone application below :
Easy to install just Click on below link and there will be install button tap on it finish !
Easy to share with your colleague or clients anyone 
No apple account required
Very Cheaper than you imagine 
If you want this application for your profile so contact:
a.kareem.tn@gmail.com

iOS NSDate -- All type of conversions Class Methods

//Get the current Device Date
+(NSDate *)getcurrentDate
{
    NSDate *CurrentDate = [NSDate date];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"yyyy-MM-dd h:mm a"];
    return CurrentDate;
}

//Get Month Year in String Format  From  Date
+(NSString *)getStringMonthYearFromDate :(NSDate *)givendate
{
    
    NSCalendar *dateCalender = [NSCalendar currentCalendar];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"MMMM-y"];
    NSString *FormattedDate = [Formatter stringFromDate:givendate];
    
    return FormattedDate;
}

+(NSDate *)getcurrentMonthYear
{
    NSDate *CurrentDate = [NSDate date];
    NSCalendar *dateCalender = [NSCalendar currentCalendar];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"MMMM y HH"];
    NSString *FormattedDate=[Formatter stringFromDate:CurrentDate];
    
    NSDate *actualDate =[Formatter dateFromString:FormattedDate];
    
    NSDateComponents *components = [dateCalender components: NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear |NSCalendarUnitHour fromDate:actualDate];

    [components setCalendar:dateCalender];
    
    [components setDay:1];
    [components setHour:4];
    
    actualDate = [dateCalender dateFromComponents:components];
    return actualDate;
}

+(NSDate *)getcurrentDateOnly
{
    NSDate *CurrentDate = [NSDate date];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"dd-MMM-yyyy"];
    NSString *FormattedDate=[Formatter stringFromDate:CurrentDate];
    return [Formatter dateFromString:FormattedDate];
}

+(NSString *)getcurrentDateInString
{
    NSDate *CurrentDate = [NSDate date];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"dd-MMM-yyyy HH:mm a"];
    NSString *FormattedDate=[Formatter stringFromDate:CurrentDate];
    return FormattedDate;
}

+(NSDate *)getcurrentTime
{
    NSDate *CurrentDate = [NSDate date];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"h:mm a"];
    return CurrentDate;
}

+(NSDate *)convertStringDateToNSDate :(NSString *)dateString
{

    NSCalendar *currentCalender =[NSCalendar currentCalendar];

    NSDateFormatter *stringToDateFormater =[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [stringToDateFormater setLocale:locale];
    [stringToDateFormater setDateFormat:@"dd MMMM y"];
    
    NSDate *fulldate = [stringToDateFormater dateFromString:dateString];
    
    NSDateComponents *components = [currentCalender components: NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear |NSCalendarUnitHour fromDate:fulldate];

    NSCalendar *dateCalender = [NSCalendar currentCalendar];
    [components setCalendar:dateCalender];

    [components setDay:1];
    [components setHour:4];
    fulldate = [dateCalender dateFromComponents:components];

    return fulldate;
}

+(NSDate *)convertStringTimeToDate :(NSString *)time
{
    NSDate *CurrentDate = [NSDate date];
    NSCalendar *currentCalender =[NSCalendar currentCalendar];
    
    NSDateComponents *components = [currentCalender components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute fromDate:CurrentDate];
    
    NSDateFormatter *stringToDateFormater =[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [stringToDateFormater setLocale:locale];
    [stringToDateFormater setDateFormat:@"h:mm a"];
    
    NSDate *date = [stringToDateFormater dateFromString:time];
    
    NSCalendar *dateCalender =[NSCalendar currentCalendar];
    
    NSDateComponents *datecomponents = [dateCalender components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute fromDate:date];
    
    [datecomponents setDay:components.day];
    [datecomponents setMonth:components.month];
    [datecomponents setYear:components.year];
    date = [dateCalender dateFromComponents:datecomponents];
    return date;
}

+(NSString *)convertTimeToString :(NSDate *)time
{
    NSDate *CurrentDate = time;
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"h:mm a"];
    NSString *timeString=[Formatter stringFromDate:CurrentDate];
    return timeString;
}

+(NSString *)convertDateToString :(NSDate *)date
{
    NSDate *CurrentDate = date;
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"MMM"];
    NSString *timeString=[Formatter stringFromDate:CurrentDate];
    return timeString;
}

+(NSString *)getcurrentTimeInString
{
    NSDate *CurrentDate = [NSDate date];
    NSDateFormatter *Formatter=[[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [Formatter setLocale:locale];
    [Formatter setDateFormat:@"h:mm a"];
    NSString *timeString=[Formatter stringFromDate:CurrentDate];
    
    
    return timeString;
}

+(NSString *)convertMinutesToTimeInterval :(NSUInteger)minutes
{
    NSTimeInterval timeInterval =minutes*60;
    NSDateComponentsFormatter *componentFormatter = [[NSDateComponentsFormatter alloc] init];
    
    componentFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
    componentFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropAll;
    
    NSString *formattedString = [componentFormatter stringFromTimeInterval:timeInterval];
    return formattedString;
}

+(NSString *)convertMinutesToTimeIntervalNumericWay :(NSUInteger)minutes
{
    NSTimeInterval timeInterval =minutes*60;
    NSDateComponentsFormatter *componentFormatter = [[NSDateComponentsFormatter alloc] init];
    
    componentFormatter.unitsStyle = NSDateComponentsFormatterUnitsStylePositional;
    componentFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropAll;
    
    NSString *formattedString = [componentFormatter stringFromTimeInterval:timeInterval];
    return formattedString;

}