How to solve iOS app upload issue-The executable contains incomplete bitcode.To compile binaries with complete bitcode





How to solve iOS app upload issue - The executable contains incomplete bitcode.To compile binaries with complete bitcode


With new Xcode, one of the problem faced by iOS developers while uploading app to App store is bitcode related errors. In this post we will learn that how to fix bitcode error in our project.

If you are not using pods then simply open your project build settings and search bitcode  as shown in picture

Set enable bitcode to NO


Set Enable Bitcode to NO, by default it's set to YES. This will fix the bitcode error and  your app will get uploaded successfully to the store.

If you are using pods in project then you have to write a script in your pod file that will disable Enable Bitcode to NO in all of your installed pods during pods installation phase or while you are updating your pods.

Script for disabling bitcode: 



post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end




Your pod file will look like this



# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'

use_frameworks!

target 'projectname' do

pod 'AFNetworking', '~> 3.0'
pod 'Fabric'
pod 'TwitterKit'
pod 'Crashlytics'
pod 'PubNub'
pod 'IQKeyboardManager'
pod 'SDWebImage', '~>3.8'
pod 'GoogleMaps'
pod 'RMUniversalAlert'
pod 'HexColors'

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end


Hope this post helps you in overcoming bitcode errors while uploading your app to app store. 

How to create PageViewController in IOS Tutorial - Swift







UIPageControl in IOS is a control that is used mostly in help screens or info screens for IOS apps. In this we are going to create a small tutorial for UIPageControl using swift language,  in which we will change background color of UIImageView as per page number selected by user on tapping on UIPageControl or swiping UIScrollViewUIScrollView is used with UIPageControl as the page control itself is set of dots and does not has display interface.

Learn how to create PageViewController in Objective C - Tutorial


Lets start our tutorial of creating page control in swift language. Create a new project with single view application template and name it UIPageViewController-swift.  Open Main.storyboard and drop UIScrollView and UIpagecontrol on to the view.

Drag UIscrollView and UIPageControl on to view
Drag UIscrollView and UIPageControl on to view

Add leading, trailing, bottom, top contraints to UIScrollView, Add constraint to page control we add horizontal and top constraint with respect to scrollview.


Add constraints to UIScrollView
Add constraints to UIScrollView

Add constraints to UIPageControl
Add constraints to UIPageControl

Now open ViewController.swift and create IBOutlets for UIPageControl and UIScrollView


 @IBOutlet var pageControl: UIPageControl?
  @IBOutlet var scrollView: UIScrollView?


and an IBAction changePage that we are going to assign to UIPageControl ValueChanged event so that we can detect that user has taped on UIPageControl.


@IBAction func changePage(){
        
    }





your ViewController.swift file will look like this


class ViewController: UIViewController {

    @IBOutlet var pageControl: UIPageControl?
    @IBOutlet var scrollView: UIScrollView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func changePage(){
        
    }
}





Open Main.storyboard and connect IBOutlets and IBAction to UIScrollView and UIPageControl

Connecting UIPageControl IBOutlet
Connecting UIPageControl IBOutlet

Connecting IBOutlet to UIScrollView
Connecting IBOutlet to UIScrollView





UIPageControl has properties to set minimum number of pages you want in your UIPageControl and which page do you want to set as current page. We will stick with default values for this tutorial




Set minimum pages and current page for UIPageControl



Open ViewController.swift , Inside viewDidLoad method, we will add UIImageView to our scroll and assign its delegate to self.We will set contentSize of scroll to number of pages we want in UIPageControl multiplied by width of UIScrollView.Then, we add three UIImageView to our scroll and set different background color to it.Add code to your viewDidLoad as shown below





var scrollWidth : CGFloat = UIScreen.mainScreen().bounds.size.width - 76.0
    var scrollHeight : CGFloat = UIScreen.mainScreen().bounds.size.height - 163.0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        scrollView?.contentSize = CGSizeMake((scrollWidth * 3), scrollHeight)
        scrollView?.delegate = self;
        scrollView?.pagingEnabled=true
        
        for i in 0...2 {
            let ih = Float(i)
            let xPos = (scrollWidth*CGFloat(ih));
            let imgView = UIImageView.init()
            imgView.frame = CGRectMake(CGFloat(xPos), 0scrollWidth,scrollHeight)
            imgView.backgroundColor = UIColor.redColor()
            if i == 0 {
                imgView.backgroundColor = UIColor.greenColor()
            }
            
            if i == 1 {
                imgView.backgroundColor = UIColor.blueColor()
            }
            
            scrollView?.addSubview(imgView)
        }
        
    }



Note: scrollWidth and scrollHeight are the width and height calculated with respect to empty space we left on top, bottom,left right or our UIScrollView with respect to view.

Run you code and you will see colored UIMageViews inside your scroll, Swipe left and right, you will see page effect. Still we have to implement our page control as user can also tap on page control in order to navigate through the different pages.


In our changePage action, we will use scrollRectToVisible  method of UIScrollView so that we can scroll our UIScrollView as per user tap on UIPageControl.


 @IBAction func changePage(){
         scrollView!.scrollRectToVisible(CGRectMake( scrollWidth * CGFloat ((pageControl?.currentPage)!), 0, scrollWidth, scrollHeight), animated: true)
    }
    



Lastly. we ned to implement scrollViewDidEndDecelerating delegate of UIScrollView so that we can calculate page number if user did not use UIPageControl and simple scroll down UIScrollView.


  
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
       setIndiactorForCurrentPage()
    }
    
    func setIndiactorForCurrentPage()  {
       let page = (scrollView?.contentOffset.x)!/scrollWidth
        pageControl?.currentPage = Int(page)

    }

    



In setIndicatorForCurrentPage, we calculated page by diving x offset of UIScrollView with its width and the assign that page to our pageControl as its current or selected page.


Download Source Code: UIPageControl in Swift

In this post we learn about how to use/create UIPageControl in iOS using swift language. You can check UIPageControl objective C version from here UIPageControl tutorial in objective C

How to create UIDocumentInteractionController in swift

 




How to create UIDocumentInteractionController in swift


In this post we will learn how to create UIDocumentInteractionController in Swift. You can check objective C version from below link


How to create UIDocumentInteractionController in ObjectiveC


Create a new project and select single view application from app templates and name it "UiDocumentController-Swift". Change your Language from objective C to swift.


Change project language to swift
Change project language to swift



Press Next and then select location for your project where you want to save the project, press create to create your project.


Open ViewController.swift file. Now we will create variable for UIDocumentInteractionController.


 var documentController : UIDocumentInteractionController!



Open your Main.storyBoard and drag UIButton to it. It's time to create an IBAction for our button so that we can open UIDocumentInteractionController on pressing it.


    @IBAction func buttontapped (sender: UIButton)  {
}


Connect your button dragged in last step on Main.storyBoard with your IBAction to UIButtonTouchUp Inside event.

Open ViewController.swift file and now we will write code to present UIDocumentInteractionController to the user.


let fileURL = NSBundle.mainBundle().pathForResource("Quotes", ofType: "png")
documentController = UIDocumentInteractionController.init(URL: NSURL.init(fileURLWithPath: fileURL!))

   documentController.presentOptionsMenuFromRect(self.button.frame, inView: self.view, animated: true)

  

In above code, first we get file url which we want to share using UIDocumentInteractionController (in our case its an image place locally in our project). After we get file path we created our UIDocumentInteractionController by using init method and pass the file url to it. Lastly, we user presentOptionsMenuFromRect method to show UIDocumentInteractionController to the user.

PresentOptionMenuFromRect take three parameters

1) frame: from where we want to the menu 
2) inView: in which we want to show the UIDocumentInteractionController
3) animated: wether you want to present your UIDocumentInteractionController animated or not

Complete Code:


 @IBAction func buttontapped (sender: UIButton)  {
      
        let fileURL = NSBundle.mainBundle().pathForResource("Quotes", ofType: "png")
        documentController = UIDocumentInteractionController.init(URL: NSURL.init 
(fileURLWithPath: fileURL!))
        documentController.presentOptionsMenuFromRect(self.button.frame, inView: self.view, animated: true)
        

    }






In this post your leaned. how to create UIDocumentInteractionController in swift language. If you are looking for Objective C Version of the UIDocumentInteractionController you can check it from here UIDocumentInteractionController - ObjectiveC  


Allow only numbers in the UITextField - IOS Tutorial





Numeric Inoput UITextField IOS Tutorial

Validations are important in IOS app development that includes user input. Sometimes we, need only
numeric values to be entered into the UITextField.

Below is the code snippet, that will make UItextField to only accept numeric input


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // For allowing backspace
    if (!string.length)
    {
        return YES;
    }
    
    // Only allows numbers to be entered in UITextField 
    if (textField.keyboardType == UIKeyboardTypeNumberPad)
    {
        if ([string rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]].location != NSNotFound)
        {
            return NO;
        }
    }

    
    return YES;

}


The above method is a delegate method of UITextField and you have to set your UITextField to point to their delegates like below line of code

phoneNumber.delegate = self;




How to create blur effect to view programmatically in IOS




Blur image effect iOS


In this post we will learn, ho can we add blur effect to our view in iOS SDK/ iPhone development. As shown in above header image.

Download the files from given below link as they are required in order to achieve the blur effect.

ImageEffects


Now open your Xcode project and import two files required to create blur effect in the file where you need to add blur effect.


#import "UIImage+ImageEffects.h"
#import "UIImage+UIImage_ScreenShot_.h"

Below is the code that creates the nice blur effect

  UIImage *imageScreenShot = [UIImage screenshot];
    UIImage *blurred = [imageScreenShot applyLightEffect];
    UIImageView *blurrImageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    blurrImageView.image = blurred;
    [[UIApplication sharedApplication].delegate.window addSubview:blurrImageView];

In above code first we capture screenshot of our view. Then we applied the blur effect to the captured screenshot image. Finally we present the blurred image to our UIImageView and add it to our app window as subview.

Complete Code:  Click to download

How to install CocoaPods and setup it with your Xcode (Objective c and swift )





CocoaPods + Xcode


CocoaPods is the dependency manager for the projects. It has number of libraries and can help you scale your projects easily. CocoaPods is built with Ruby and is installable with the default Ruby available on your mac machine. The main advantage of Cocoapods is that the libraries are hosted on other machine and you can easily integrate to your project by simply modifying the pod file and hit one command to install/update the pods (you can refer them to as your libraries or frameworks). Below are the steps to install Cocoapods and use them with your project

** Make sure you have installed/updated command line tool in your Mac machine. You can check this by opening Xcode, navigating the menu to Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update.

Check for Command line tools in Xcode

If you see command line tools then install those first. If they are installed then please proceed further.  Open terminal and execute below commands

1)  sudo gem install cocoapods - This will installed cocoa pods in your mac machine.


For El Capitan OSX use -  sudo gem install -n /usr/local/bin cocoapods

The above command will ask for your system password, if any and will take some time. The terminal will show you a waring message please ignore this.

Executing sudo gem install cocoapods in the terminal
Executing sudo gem install cocoapods in the terminal


CocoaPod installed successfully
CocoaPod installed successfully

2)  Set up pods with your Xcode project. Open terminal and type the change directory command

$ cd path of your XCode project root directory (where your ProjectName.xcodeproj file is placed)

$ pod setup - Setup Cocoapod master repo

$ touch podfile - create a blank pod file, it's the place where you will write your libraries name you want to use in your project.

$ open -e podfile - will open pod file in text editor

write your libraries name as show below. Save and close text editor.


Pod file
Pod file


NOTE: Use ( control + ” ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without control button it shall be added as curly single quote which will give error while installation of file.


$ pod install - install all the libraries written in the pod file


You should see output similar to the following:

Updating spec repo `master’
After successful downloading/installation of any single library, It will generate ProjectName.xcworkspace in your project root directory. From now use this workspace to open your project. When you open your project work space you will see Pod is also added as another Xcode project with your Xcode project. If you open Pod it will show all libraries.
For your next project your don’t need to install the cocoa pod again in your mac machine just open the terminal and setup the Pod in root directory of your Xcode project and always remember these 3 commands :
  • 1. $ touch podfile
  • 2. $ open -e podfile
  • 3. $ pod install
To update Pod libraries : $ pod update
To check POD version : $ pod –version
To update CocoaPods : $ gem install cocoapods or use sudo at start if getting error “You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.”
NOTE: Article originally taken from below link