Showing posts with label ios. Show all posts
Showing posts with label ios. Show all posts

Saturday, September 15, 2012

Fix the iOS code signing issue when using Jenkins


This week I setup the Jenkins on my Mac and try to build iOS applications. unfortunately I got the code signing issues, either I use xcode plugin or xcode command line tool. Through a couple days of googling and I could not find any solution that works for me, but I finally solve this issue by myself through different try out, and the solution is such an easy, now I would like to share with my solution.

The core reason is Jenkins is running as daemon mode in Mac, just assume it is a different user - "Jenkins", so it will not have access to the keychain or provision profile as a you login using your credentials, which cause the code signing issue.
I found I have following 2 errors

1. "Code Sign error: There are no valid certificate/private key pairs in the default keychain"
Solution: Copy your iPhone developer certificate from "login" keychain to "System" keychain.
Detailed steps:
  open the "Keychain Access" application, click the login tab, right click the certificate like "iPhone Developer: your_name (XXXXXXX)", choose copy, then click the "System" tab, right click mouse, choose "Paste 2 items"; you might need to do the same thing with the certificate like "iPhone Distribution: your_name".

After doing this, you will get the second error.
2. "Code Sign error: Provisioning profile 'xxxxx-xxxx-xxxx-xxxxx' can't be found"
Solution: Copy the provision profile to Jenkins user folder.
The provision profile is under in the folder
/YourUserName/Library/MobileDevice/Provisioning Profiles,
for example in my machine, the provision profile files are under /Users/steve/Library/MobileDevice/Provisioning Profiles
In the mac, the Jenkins will be in /Users/Shared/Jenkins, create the following folder:
/Users/Shared/Jenkins/Library/MobileDevice/Provisioning Profile,  then copy the .mobileprovision file to this folder.

After doing this, the code signing issues will be fixed. Hope my finding will be helpful to other Jenkins users.

Wednesday, February 22, 2012

How to read a file in Xcode project

Recently I got stuck with an objective C problem, Given a text file in your Xcode project, how could I read this text file in my Xcode 4.2 project?
For example, you got a text file called test.txt, it has some contents. In your Xcode project, you need to read its file and print its content. It sounds easy at the beginning, but end up really tough, especially you are new with the latest version of Xcode.
The key problem is you need to make sure the file test.txt is put as the same folder as the build target file, which is the Products folder, otherwise you will always get the file not existed exception.

Through several times try out, finally I figure out how to do it.

1. Add your file into project
   Select File - Add File into xxx, chose the created file into project.
2. Add a "copy file" build phase
    View - Navigator - Show Project Navigator, chose Project, select targets, select Build phase,
    and click "Add Build Phase", add "Copy files";
    in the new Copy Files build phase, choose
      Destination - "Production Directory"
     and click "+" symbol, then choose the file test.txt in your project.

How to test if the file was added in the Product folder or not?
After press the "Run" button, you will see the executable target file under the "Product" folder of your Xcode project,select the target file, right click, select "Show in Finder", then the Product Folder will pop up in the Finder Application, then you should see the test.txt file in the same folder.