To create an extension for iOS or tvOS you have to do it in two parts. The first part would be to add the extension itself, along with the required files, and the second is to create the functions and macros/constants that the extension requires.
The functions and constants are added using placeholder files to group them together, so you'd add a placeholder and then define the functions and macros as explained in the section here. To add the rest of the files though you need to first tick the iOS and/or the tvOS check-box in the Additional Features section of the editor to open up the relevant Extension Properties window (the image below shows the iOS properties window, but the tvOS window is exactly the same):
Here you can give the following details:
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Check if any superclasses implement this method and call it
if([[self superclass] instancesRespondToSelector:@selector(application:willFinishLaunchingWithOptions:)])
return [super application:application willFinishLaunchingWithOptions:launchOptions];
else
return TRUE;
}
Code Injection can be used for iOS/tvOS extensions in the same way as described on the Android Extensions page: see Code Injection.
The following tags are available for the iOS and tvOS platforms:
YYIosPlist
YYIosEntitlements
YYIosCocoaPods
YYIosCocoaPodsDependencies
YYIosBuildRules
YYIosBuildSettingsInjection
YYIosScriptPhase
YYIosCFBundleURLSchemesArray
YYIosLSApplicationQueriesSchemesArray
YYIosPrivacyManifest
YYTvosPlist
YYTvosEntitlements
YYTvosCocoaPods
YYTvosCocoaPodsDependencies
YYTvosBuildRules
YYTvosBuildSettingsInjection
YYTvosScriptPhase
YYTvosCFBundleURLSchemesArray
YYTvosLSApplicationQueriesSchemesArray
YYTvosPrivacyManifest
The runtime location where the code is injected will depend on the type of the tag:
Tag Type | Injection Path |
---|---|
Entitlements | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}\ ${YYXCodeProjName}.entitlements |
info.plist | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}\ Supporting Files\${YYXCodeProjName}-Info.plist |
infoPlist.strings | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}\ en.lproj\InfoPlist.strings |
project.pbxproj | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}.xcodeproj\ project.pbxproj |
xcscheme | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}.xcodeproj\ xcshareddata\xcschemes\${YYXCodeProjName}.xcscheme |
PrivacyManifest | {RUNTIME}\ios\TemplateProject\${YYXCodeProjName}\Supporting Files\PrivacyInfo.xcprivacy |
NOTE These paths are only for VM. For YYC, injected code will go into the {RUNTIME}\yyc\ directory, where the paths may or may not be equivalent to those for VM.
You can also inject tags conditionally. See: Conditional Injection
Within the text files added to your extension (see: Adding Files), you can inject code from the Code Injection window by mentioning a tag inside ${ }. For example, say you have a file with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
${YYIosMyInjectionTag}
</dict>
IMPORTANT You can create your own tags for this use. Such custom tags must start with YYIos or YYTvos (depending on the platform).
The ${YYIosMyInjectionTag} part here will be replaced with the contents of the <YYIosMyInjectionTag> </YYIosMyInjectionTag> group from the extension's Code Injection window.
You can create a folder called "iOSProjectFiles" in the folder of your extension (alongside its .yy file). Any files placed in this folder will be moved to the root of the generated Xcode project at compile time, and can also take injection tags as described above.
If your extension has had any System Frameworks or 3rd Party Frameworks added, these will now be listed in the Extension Properties window, with each one having a check-box beside it. If you mark the check-box, you are enabling weak linking, which is useful should you need to "override" any symbol from the included library with your own value, but it should be noted that doing so will slow linking down.
For information on your creating native extensions for iOS, see Source Examples; and for information on using CocoaPods in extensions, see the following guide: