Best Practices: Difference between revisions

From iPhone Development Wiki
(→‎Packages: Clarity and tell people what to do about .DS_Store files)
(→‎Applications and Tweaks: Make note of what HBRespringController calls through to)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Applications and Tweaks ==
== Applications and Tweaks ==
* Avoid referring to <code>/var/mobile</code> directly - use <code>NSHomeDirectory()</code> if your code is running as mobile!
* <code>NSHomeDirectory()</code> doesn't guarantee that it will return <code>/var/mobile</code>, especially from within sandboxed processes.
** If your code is running as root, use extra caution when writing files that mobile can access - you might break the file's access permissions.
** If your code is running as root, use extra caution when writing files that mobile can access - you might break the file's access permissions.
** App Store apps will return their sandbox data path from <code>NSHomeDirectory()</code>.
** App Store apps will return their sandbox data path from <code>NSHomeDirectory()</code>.
* See [[MobileSubstrate Pitfalls]] for additional guidelines regarding tweaks.
* See [[Cydia Substrate Pitfalls]] for additional guidelines regarding tweaks.
* You should consider the UDID deprecated like Apple has for some time, but if you need the device's UDID, use [[libMobileGestalt.dylib]].
* You should consider the UDID deprecated like Apple has for some time, but if you need the device's UDID, use [[libMobileGestalt.dylib]].
* If you need to use singletons, see [[singleton pattern]] for advice.
* If you need to use singletons, see [[singleton pattern]] for advice.
* If you need to respring from a tweak and you are targeting iOS 6 - 7, kill backboardd instead of SpringBoard. Killing SpringBoard has been known to cause some issues regarding the backlight. For iOS 8 and newer, if possible, use <code>-[HBRespringController respring]</code> from [https://github.com/hbang/libcephei/blob/master/HBRespringController.x libcephei] for a more appropriate way to respring. Simply killing the processes can destroy battery usage data (the feature since iOS 8) of the user.
* If you need to respring from a tweak and you are targeting iOS 6 - 7, kill backboardd instead of SpringBoard. Killing SpringBoard has been known to cause some issues regarding the backlight. For iOS 8 and newer, if possible, use <code>[[FBSSystemService#Relaunch SpringBoard with relaunch URL|SBSRelaunchAction]]</code> or <code>-[HBRespringController respring]</code> from [https://github.com/hbang/libcephei/blob/master/HBRespringController.x libcephei] for a more appropriate way to respring. Simply killing the processes can destroy battery usage data (the feature since iOS 8).
 
== Packages ==
* Do not create mobile-owned files and/or directories in your package. Stay out of mobile's home directory!
** All package files are installed as root. Your software should create any required files or directories at runtime.
** This is doubly important for preferences. A user's preferences do not belong in a package: if preferences are stored in the package, they will be overwritten when you release an update, and deleted when the user uninstalls your software (even temporarily!)
* Do not use postinst/preinst/extrainst_ for file management purposes!
** Do not store in the package files or directories that your software could create.
** Do not enforce permissions that your package should contain. dpkg uses an expressive packaging format that has support for permissions, ownership, and links. Use that support!
* Make sure your package doesn't include hidden .DS_Store, ._*, or thumbs.db files.
** <code>export COPYFILE_DISABLE=1</code> will disable resource forks (._* files) being included on OS X with Theos.
** Adding <code>find . -name '.DS_Store' -type f -delete</code> to your package staging commands in Theos/DragonBuild will ensure they are deleted before packaging.

Latest revision as of 03:42, 29 May 2021

Use the following guidelines to avoid your package or app being fragile and to increase the chances of it being accepted by a community host.

Applications and Tweaks

  • NSHomeDirectory() doesn't guarantee that it will return /var/mobile, especially from within sandboxed processes.
    • If your code is running as root, use extra caution when writing files that mobile can access - you might break the file's access permissions.
    • App Store apps will return their sandbox data path from NSHomeDirectory().
  • See Cydia Substrate Pitfalls for additional guidelines regarding tweaks.
  • You should consider the UDID deprecated like Apple has for some time, but if you need the device's UDID, use libMobileGestalt.dylib.
  • If you need to use singletons, see singleton pattern for advice.
  • If you need to respring from a tweak and you are targeting iOS 6 - 7, kill backboardd instead of SpringBoard. Killing SpringBoard has been known to cause some issues regarding the backlight. For iOS 8 and newer, if possible, use SBSRelaunchAction or -[HBRespringController respring] from libcephei for a more appropriate way to respring. Simply killing the processes can destroy battery usage data (the feature since iOS 8).