Getting Started: Difference between revisions

From iPhone Development Wiki
(→‎Learning Objective-C: more detail for beginners)
(→‎Learning Objective-C: turning table into descriptions, removing iOS 6-specific links)
Line 1: Line 1:
== Learning Objective-C ==
== Learning Objective-C ==


If you have no programming experience, you'll first need to learn a lot about Objective-C and developing ordinary applications for iOS. [https://www.codeschool.com/paths/ios Code School has a free web-based course for beginners] that can give you a taste. You can also try the [http://www.codecademy.com/ free web-based courses offered by Codecademy] - they're not about Objective-C or iOS, but they can give you a general sense of what programming is like. For further study:
If you have no programming experience, you'll first need to learn a lot about Objective-C and developing ordinary apps for iOS.


{| class="wikitable"
[https://www.codeschool.com/paths/ios Code School has a free web-based course for beginners] that can give you a taste. You can also try the [http://www.codecademy.com/ free web-based courses offered by Codecademy] - they're not about Objective-C or iOS, but they can give you a general sense of what programming is like.
|-
! Title
! Author
! Link
|-
| Programming in Objective-C
| Stephen G. Kochan
| [http://www.amazon.com/Programming-Objective-C-Edition-Developers-Library/dp/032188728X Amazon]
|-
| Objective-C Programming: The Big Nerd Ranch Guide
| Aaron Hillegass
| [http://www.amazon.com/Objective-C-Programming-Ranch-Guide-Guides/dp/0321706285 Amazon]
|-
| Apple's Developer Documentation
| Apple
| [https://developer.apple.com/xcode/ Apple]
|-
| The Core iOS 6 Developer's Cookbook
| Erica Sadun
| [http://www.amazon.com/gp/product/0321884213/ref=s9_simh_gw_p14_d0_i2?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0PZZG8HW1055FMCBXYCM&pf_rd_t=101&pf_rd_p=1389517282&pf_rd_i=507846 Amazon]
|-
| iOS 6 Programming Cookbook
| Vandad Nahavandipoor
| [http://www.amazon.com/iOS-Programming-Cookbook-Vandad-Nahavandipoor/dp/1449342752/ref=pd_sim_b_3 Amazon]
|-
| The New Boston Video Tutorials
| Videos by Bucky
| [http://thenewboston.org/list.php?cat=33 The New Boston]
|}


See also: [http://iphonedevsdk.com/ unofficial iPhone Dev SDK forum] and [http://stackoverflow.com/questions/tagged/ios Stack Overflow].
For further study:
 
* Apple's developer documentation - see [https://developer.apple.com/xcode/ the Xcode page] and [https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html#//apple_ref/doc/uid/TP40011343 Start Developing iOS Apps Today].
 
* Videos: [https://itunes.apple.com/us/course/developing-ios-7-apps-for/id733644550 Stanford's "Developing iOS 7 Apps for iPhone and iPad" class on iTunes U] and [http://thenewboston.org/list.php?cat=33 The New Boston video tutorials].
 
* Books: [http://www.amazon.com/Programming-Objective-C-Edition-Developers-Library/dp/032188728X ''Programming in Objective-C'' by Stephen G. Kochan] and [http://www.amazon.com/Objective-C-Programming-Ranch-Guide-Guides/dp/0321706285 ''Objective-C Programming: The Big Nerd Ranch Guide'' by Aaron Hillegass].
 
* Forums: [http://iphonedevsdk.com/ unofficial iPhone Dev SDK forum] and [http://stackoverflow.com/questions/tagged/ios Stack Overflow].
 
Ideally you'll get to a point where you're comfortable writing and running code for iOS. If you're already there, definitely keep reading!


== Setting up Theos ==
== Setting up Theos ==

Revision as of 23:51, 16 January 2014

Learning Objective-C

If you have no programming experience, you'll first need to learn a lot about Objective-C and developing ordinary apps for iOS.

Code School has a free web-based course for beginners that can give you a taste. You can also try the free web-based courses offered by Codecademy - they're not about Objective-C or iOS, but they can give you a general sense of what programming is like.

For further study:

Ideally you'll get to a point where you're comfortable writing and running code for iOS. If you're already there, definitely keep reading!

Setting up Theos

Follow this guide to set up your Theos environment by installing Theos, getting your headers, and creating your first project: Theos/Getting Started. These links may also be helpful: guide on Stack Overflow , this Theos documentation by theiostream, and Theos Install Script.

Finding example projects

Here is a list of just a few of the many open source projects that can be used as examples: Open Source Projects.

Not finding what you are looking for? Try searching through GitHub for iOS Tweaks with a simple trick, "extension:xm".

Example:

extension:xm SBAwayController

Using the above code will search GitHub for all files with the extension .xm (because Theos by default creates a Tweak.xm file when creating a new tweak). The example above will result in finding tweaks that reference SBAwayController. Not all developers use the .xm file extension, but a large number do, and this will help you in finding those examples.

Looking at classes

You can extract Objective-C class interfaces with class-dump, class_dump_z (a more efficient version of class-dump), or classdump-dyld. Remember that the resulting files are not the original headers, so use them with caution.

You can also find other developers have done this process for many frameworks and compiled their work into github repositories. Here's two of them:

Prototyping a tweak

You can use Cycript to explore running processes. For a demo, see Adam Bell's JailbreakCon talk (example code and slides).

Building your tweak

After prototyping you will want to make your tweak into a project to build it and debug it. To achieve this you will most likely use Theos. It is available for different platforms including iOS and Mac OS, and, to a certain extent, Linux. On Mac OS you can use Xcode's command line tools but for the other platforms you should use a toolchain. On iOS there are two available toolchains (On-device_toolchains).

Debugging

You can use gdb. See pod2g's instructions for getting gdb running on your device. Note that the path beginning with /Developer is out of date; it should begin with /Applications/Xcode.app/Contents/Developer instead.

See System Log on TheiPhoneWiki for useful tips about accessing the device's syslog.

A few problems you may run into while getting started

Whenever I run programs I compile with your toolchain, they are immediately "Killed". I hate Apple :(. iOS only wants to run signed code. Jailbreaks patch the signature verification out of the kernel, but you still need to at least add a valid CodeDirectory to the binary that contains SHA1 hashes of the executable. See Code Signing for a few ways to do this.

I tried copying a graphical program to the iPhone, and ran it from the command line. I am nearly 100% certain my program is correct, and I did your codesign instructions, but it doesn't work. You can't run things from the command line, you have to run them from SpringBoard.

OK, but when I copied the file to /Applications it didn't even show up in SpringBoard. iOS caches the Info.plist files of all installed applications in a centralized place. The fastest/bestest way to handle this cache is to install UIKit Tools and then run its uicache as mobile.

When I add setuid bits to my program, it no longer starts up and syslog doesn't seem to provide any useful information, either (True?). I am not quite certain what is preventing this. However, it is easy to defeat: replace your program with a two line shell script that, in turn, runs your program. Example, maybe MyProgram (setuid) gets renamed to MyProgram_, and MyProgram (not setuid) becomes the script:

#!/bin/bash
dir=$(dirname "$0")
exec "${dir}"/MyProgram_ "$@"

Publishing your package in a default repository

When you've completed a project (including testing), you may want to submit it to one of Cydia's default repositories for distribution. These are your options, with links to information about submitting:

If you aren't sure which to pick, look up what your favorite developers use, or ask other developers for suggestions. If you have questions, email is usually the best way to get in contact with repository managers.

For questions about the Cydia Store system for paid packages, you can ask your favorite repository manager; they've helped many developers figure this out.

Some guides on other sites

Theos challenges

This section is a set of tweaks/apps that can be created with Theos for new or experienced developers to practice with.

Title Description Example Need Help?
LaunchNotifier Show a UIAlertView on the screen after any app has been launched. The title of the UIAlertView is the name of the app being opened. Example Guide
AskLaunch Show a UIAlertView after tapping an app, asking the user whether they want to launch it or not. Example
TransparentSBEditor Make the SpringBoard icons transparent while editing, instead of jittering. Example

If you're interested in ideas for something else to build, the "Request" tag on /r/jailbreak has lots of tweak ideas from real people.