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;

}

Thursday, 20 November 2014

iOS Phone No Validation



-(BOOL)checkValidation :(NSString *)phoneNo
{
    NSString *phoneRegex = @"((971)\\d{9})";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    
    BOOL phoneValidates = [phoneTest evaluateWithObject:phoneNo];
    return phoneValidates;
    

}

Thursday, 24 July 2014

Youtube Embeded not playing in landscape mode in iOS6 and above

Just Copy and paste below code in your AppDelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
    
    if (window && [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
    

}

Saturday, 12 July 2014

Play Youtube video in webview with HTML

Copy and Paste below code and load in your webview:

NSURL *myURL =[NSURL URLWithString:@"http://www.youtube.com/v/zah99ETVOz4"];

NSString *embedHTML = @"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"212\" height=\"172\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"270\"></embed></object></div></body></html>";

NSString *html = [NSString stringWithFormat:embedHTML, myURL,myURL,myURL];





[YourWebView loadHTMLString:html baseURL:nil];

Monday, 30 June 2014

Add Event into iphone Calendar

//Add Event kit framework
EventKit.framework
//import 
#import <EventKit/EventKit.h>

//Copy below code and enjoy

-(IBAction)AddEvent:(id)sender
{
    NSString *dateString = @"Jul 09,2014 00:00";
    
    //Create a formater
    NSDateFormatter *formater =[[NSDateFormatter alloc] init];
    [formater setDateFormat:@"MMM dd,yyyy HH:mm"];
    NSDate *startDate =[formater dateFromString:dateString];
    
    NSLog(@"current date %@",[NSDate date]);
    EKEventStore *store = [[EKEventStore alloc] init];
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) { return; }
        EKEvent *event = [EKEvent eventWithEventStore:store];
        event.title = @"My Birthday";
        event.startDate = startDate;//[NSDate date]; //today
        event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
        [event setCalendar:[store defaultCalendarForNewEvents]];
        NSError *err = nil;
        [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
        NSString *savedEventId = event.eventIdentifier;  //this is so you can access this event later
    }];
    

}

Friday, 6 June 2014

Convert mp3 to caf format


Open terminal and go to the folder where your mp3 file is placed then write below command and enter 

afconvert -f caff -d LEI16@44100 song.mp3 song.caf

Thats all 

Thursday, 5 June 2014

Download Manager for iOS

Small effort by ideamakerz.
This download manager uses the iOS 7 NSURLSession api to download files.
  1. Can download files if app is in background.
  2. Can download multiple files at a time.
  3. It can resume interrupted downloads.
  4. User can also pause the download.
  5. User can retry any download if any error occurred during download.


You can download this amazing tool for your development from here.
Install in your device from here.


Tuesday, 3 June 2014

How to right function in swift language

func whatsYourStatus (age:Int, name:String) ->(String)
{
    var answer=""
   
    if(age < 0)
    {
        answer = "you need to born first!"
    }
    else if(age < 13)
    {
        answer = "you are not ready for programing"
    }
    else if(age >= 13 && age <= 19)
    {
        answer = "you can start programing"
    }
    else if(age > 19 && age <= 25)
    {
        answer = "you are an expert of Objective-C"
    }
    else if(age > 25 && age <= 30)
    {
        answer = "you are not ready for swift"
    }
    else if(age > 30 && age <= 35)
    {
        answer = "you are an expert of swift"
    }
    else if(age > 35)
    {
        answer="you are retired , have time with your family"
    }
    return "\(name) \(answer)"
}

whatsYourStatus(45, "Kareem")

Wednesday, 14 May 2014

SQLite DB Integration in iOS -- Basic Tutorial ,(In Process ....)

This Post is in under Development, it will be final soon....................

This post is the basic SQLite integration in iOS project for newcomers, if you are experienced developer then it will not be helpful for you :



To create database and manage tables you can add SQLite Manager Add-Ons in Firefox please follow the below guideline:




Open SQLite Manager from Firefox:



Creating new Database:

Creating a Table :





Optional: 
For SQLite DB this tool is also very helpful, if you wish to use just open sqlite file with Navicate:





Drag your SQLite database file into your project:


Make sure create group for any added folder is selected and  add to target your project as show in belowimage.



Copy Database into Document Directory:

You can call this method in didFinishLaunchingWithOptions in Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    //Copy Database into Document Directory
    [self copyDB];
}

-(void)copyDB
{
    //sample is the name of your database
    NSString *str = [[NSBundle mainBundle]pathForResource:@"sample" ofType:@"sqlite"];
    NSString *docpath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *destPaht = [docpath stringByAppendingPathComponent:@"sample.sqlite"];
    NSLog(@"databse path %@",destPaht);
    NSFileManager *mgr = [NSFileManager defaultManager];
    if (![mgr fileExistsAtPath:destPaht])
    {
        [mgr copyItemAtPath:str toPath:destPaht error:nil];
    }
    
}



//Below is class method for Select Query to get all records from table:
+(NSMutableArray *)GetAllRecords
{
    
    NSMutableArray *finalempArr =[NSMutableArray array];
    sqlite3 *database;
    if (sqlite3_open([Database_Path UTF8String], &database) == SQLITE_OK)
{
NSString *selectSql;
selectSql = [NSString stringWithFormat:@"SELECT * FROM records"];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [selectSql cStringUsingEncoding:NSUTF8StringEncoding], -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
                NSMutableDictionary *empDic =[NSMutableDictionary dictionary];
                //here we get all column entries from table
                NSString *emp_id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,0)];
                NSString *emp_name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,1)];
                NSString *emp_age = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,2)];
                NSString *emp_address = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,3)];
                NSString *emp_cell = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,4)];
                
                //adding entries in dictionary optioanl
                [empDic setValue:emp_id forKey:@"id"];
                [empDic setValue:emp_name forKey:@"name"];
                [empDic setValue:emp_age forKey:@"age"];
                [empDic setValue:emp_address forKey:@"address"];
                [empDic setValue:emp_cell forKey:@"cell"];
                
                [finalempArr addObject:empDic];
                empDic=nil;
}
sqlite3_finalize(statement);
}
else
{
NSLog(@"Error");
}
sqlite3_close(database);
        database=nil;
}
else
{
 NSLog(@"Database cant open");
}
return finalempArr;

}

You can call above method like this:

[DatabaseClass GetAllRecords];

You can download Sample SQLite Integration Code from  here.