How to link and unlink frameworks depending on Deployment in iOS - ios

i want to know how to link frameworks and unlink automatically depending on deployment target.
For example Digits and Twitter Core frameworks are for minimum deployment target iOS 8.0 so i want to link these frameworks when app is running on iOS 8 and higher and when running on iOS 7 i do not want to link.
i also checked setting the Framework options in Build Phases to Optional but its did not work.
How i can specify these frameworks in Bridging Header file so that depending on Deployment that will be linked and unlinked automatically.

You have to create different build targets based on you requirement. While releasing the app to app store you have to release different application which is built with corresponding target. Yo can't unlink on runtime

Related

What is the difference between "Embedded Binaries" in Xcode General tab and "Embeded Frameworks" in Build Phases tab?

What is the difference between "Embedded Binaries" in Xcode General tab and "Embeded Frameworks" in Build Phases tab?
And What is the difference between "Linked Frameworks" in General tab and "Link Binary with Libraries" in Build Phrases tab?
There are some articles explain them
What is the difference between Embedded Binaries and Linked Frameworks
Link Binary with libraries VS Embed Frameworks
But I still don't know the differences between the ones in General tab and the ones in Build Phases tab.
Embedded Binaries:
A Binary is a compiled file and in this case, it's a Framework in iOS environment. When you are using a framework which is not available in the iOS device, such as Alamofire, SDWebImage, you need to configure your xcode project, such that it copies the Binary File into the IPA while exporting. If its not copied, the IPA will not work as the code required to run Alamofire and SDWebImage is not available in the iOS environment or the IPA.
In the case of Frameworks developed by Apple, which is already available in the iOS enviroment, you dont have to add them to the Embedded Binary, such as UIKit, Foundation.
If you are running an API which is supported from iOS 12, in a device with iOS 10, the application will crash as the iOS 10 environment is not aware of the API in iOS 12. This issue is address in Android Development using support library which is a Binary in Android, which has all the latest API and can be used in different versions of Android OS.
Linked Frameworks and Libraries
Here you should add the apple's default frameworks and libraries. It is added to indicate that the current Target is using those Frameworks, since LLVM is available in Xcode now, you dont have to do this as its automatically linked with the help of LLVM
Embedded Frameworks
Link Binary With Libraries
To understand 3 & 4, you need to get an idea about Build Phases.
Build phases are some of the processes that happens when the code is compiled to a binary with is exported as an IPA file. In short, they are processes that happen when you are building your project.
When you are building your project, the steps listed in the build phases is done one after the other,
3 & 4 are two processes done during the Build process.
This process, embedds the library to the Binary Compiled file for use in the application.
This process links the compiled binary with the library.

How to build a framework for all platforms in single Xcode project?

Previously to build a framework for particular platform(macOS, iOS), I used to maintain different projects in Xcode and build separately.
My code mostly depends on sqlite3.h and a wrapper class written in Swift.
Is there a way to maintain all the frameworks under one xcode project?
I searched but I didn't get any tutorials on the web.
Thank you.
yes of course xcode can handle this for a long time. you simply create your framework project and then add targets for iOS, macOS, tvOS and watchOS.
the plus sign below the target pane allows you to add more target. or just duplicate your existing target and change sdk and platform settings.

xcode: ios dynamic frameworks show "Entitlements 0" when submitting

I've searched for hours but cannot find an answer. I have a xcode project with Cocoapods 0.39. in my Podfile i use !use_frameworks to enable a external Swift library in my Objective-C project.
But when i validate (or submit) with xcode, i get the codesigning dialog box. Normally only my app is shown but now it also shows the dynamic framework (cocoapods dependency). I think this is because of the !use_frameworks option.
The screenshot shows the dialog:
Screenshot
I can upload my binary to testflight and it will get processed but is this something i need to worry about? Is likely that apple will reject my app because of this?
There is nothing to worry about it, cocoapods are usually shown in codesigning dialog box, every cocoapod dependency that you will use will be shown there, there will be no issue and Apple will also not reject cocoapods
If you can upload your binary, I guess your minimum deployment target is iOS 8.0 or above, also in your Swift source code, you must
import AXRatingView
If your App's minimum deployment target is iOS 7, you can do this in the Podfile
#use_frameworks!
and comment
//import AXRatingView
then in your ...Bridging-Header.h
#import <AXRatingView/AXRatingView.h>
My App's minimum deployment target is iOS 7.0, ready for sale now.

How to extend iOS app to tvOS

I have an iOS app that I need to extend to tvOS.
All the information that I found are explaining how to start from scratch!
Is there any way to extend my app to tvOS or I should start a new project with it?
Update1:
My question is: How to extend my existing project to support tvOS without building it from scratch?
Update2:
Jess Bower point on Apple's website:
Empower customers to enjoy their favorite apps on both iOS and the new
Apple TV with a single purchase by enabling universal purchase for
your app on the App Store.
Which means that we need to create a new bundle on our existing project and enable "universal" purchase so it will count as one app on App Store.
The tvOS SDK is based off of iOS, but is not interchangeable. Unlike when the first iPad was released, the new Apple TV will not be capable of running iOS apps.
The AppStore for the TV will only include apps built specifically for tvOS.
For any iOS developers looking to create apps for Apple TV, I'd recommend checking out the new documentation page: https://developer.apple.com/library/content/documentation/General/Conceptual/AppleTV_PG/index.html#//apple_ref/doc/uid/TP40015241-CH12-SW1
Specifically, check out the Inherited iOS Frameworks section to give you a sense of what will work out of the box from your existing iOS projects.
In Xcode 7.1 (which introduces tvOS SDK) you can add a tvOS target as any other (File -> New -> Target... -> tvOS -> ...) and it supports both Objective-C and Swift, so yes - it's possible to share code between your iOS and tvOS app, you just need to check your source target membership and enable it on your tvOS target. To extend the purchases across iOS and tvOS app we should use Universal Purchases.
Took me a little while to find all the things needed to change but this list should cover it.
click iOS target and duplicate
change base sdk of new tvOS target to tvOS latest
make copy of info.plist and have tvOS point to that one
make all the tvOS icons and launch images
set TARGETED_DEVICE_FAMILY to 3 for the tvOS build settings
add any new tvOS specific versions of code e.g. without shouldAutorotate, prefersStatusBarHidden etc.
I also believe that adding a new target for tvOS is the way to go, especially if you have lots of objective-c or swift code to share between projects.
For those instances where there might be some tvOS-unsupported types in your shared code, I have used these preprocessor symbols to provide alternate code snippets for tvOS:
#if TARGET_OS_IOS
// iOS-specific code
#elif TARGET_OS_TV
// tvOS-specific code
#endif
Just to list out some limitations and challenges:
1. There is no persistent local storage for apps on Apple TV. Data must be stored on iCloud. 2. The maximum size of an Apple TV app is limited to 200MB. On-demand resources (app contents that are hosted on the App Store) should be used. Benefits are smaller app size and lazy loading of app resources. 3. The UI is drastically different. Human Interface Guidelines must be followed as per the doc. 4. Creating a Client-Server App using JavaScript and TVML framework. 5. Controlling the UI touch focus. UIFocusEnvironment controls focus-related behavior for a branch of the view hierarchy. UIViewController conforms to UIFocusEnvironment protocol. 6. Creating Parallax Artwork You have to create a LSR image with Xcode and then use terminal to create a LCR image. A UIImage object can display a LCR image correctly.
A new target has to be added for tvOS. There are two ways to do that
Add a new target through File > New > File...> tvOS Target.
Duplicate an existing iOS target and change TARGETED_DEVICE_FAMILY to 3 and "Supported Platforms" to tvOS in "Build Settings"
Pods need to be added to the tvOS target using pod install. There could be a different list of pods that you can/want to use in tvOS. Pods for different targets can be separated in Podfile using:
target 'iOS TARGET NAME' do
pod 'podname', :git => 'https://github.com/name.git'
end
target 'tvOS TARGET NAME' do
pod 'podname', :git => 'https://github.com/name.git'
end
Most Pods at the moment do not support tvOS. For those Pods, here are the steps to make them work in your project:
Clone the git repo on your local disk
If a version of the pod is being used in another target (iOS target), change the name, otherwise CocoaPods will complain: e.g. RestKit --> RestKitTV and use :path In Podfile to point to the location of the cloned repo:
pod 'RestKitTV', :path => 'Other/RestKitTV'
Update the podspec file in the cloned repo:
Modify the name to be compatible with the new name
Change the platform to tvOS or add tvOS to the list of supported platforms
Pod::Spec.new do |s|
..
s.platform = :tvos
..
end
OR
Pod::Spec.new do |s|
..
s.tvos.deployment_target = '9.0'
s.tvos.exclude_files = 'framework/Source/Mac', ....
s.tvos.frameworks = ['OpenGLES', 'CoreMedia', 'QuartzCore']
..
end
Add files to the target:
Add source code (.m files) to "Compile Sources" of "Build Phases" for the target
Add images to "Copy Bundle Resources"
Add frameworks to "Link Binary with Libraries". Note that not all frameworks are compatible with tvOS
Use TARGET_OS_TV and TARGET_OS_IOS macros to separate tvOS non-compatible code
#if !TARGET_OS_TV
*iOS only code*
#else
*tvOS only code*
#end
+Simon-Tillson answer is correct, however I had some backwards compatibility issues with iOS 8.1 and below SDK's where TARGET_OS_IOS was not defined (for older Xcode versions)
The following code fixes that and works the same for iOS 9.0/9.1 SDK + and previous 8.1 and less SDKS.
#if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV)
// iOS-specific code
#elif TARGET_OS_TV
// tvOS-specific code
#endif
In case of my project, I simply added a new target to the existing iOS project, and modified some code appropriately (using #if os(tvOS/iOS) in a few areas). I am now able to run the same app either on iOS devices or Apple TV.
The only framework missing in tvOS was WebKit (which was necessary to render rich text), and I needed to come up with an alternative mechanism.
I am going to open source this project soon (before the end of October), so that other people can take a look.
Don't forget to change the Base SDK into TVos 9.x in the build settings. It's necessary for the Tv simulator to show up

Xcode IOS Deployment target Options

In Xcode there are 5 columns when entering the Deployment target like shown below.
Resolved / AppName / Config (Pods) / App Name/ IOS Default
What are all these columns/options for? Is there not just one IOS Deployment Target for the app.
I understand that because I use Cocoa pods there could be a separate deployment type for the pods, but why the two columns with app name and ios default etc?
Each of the columns is a different place in the build system "hierarchy" where the value can come from. The rightmost is the default built into Xcode; moving from right to left, there's the overall project, the config file from Cocoapods, the per-target config, and the value that will actually take effect. If your project is part of a workspace, there's a level there, too.
You're right that for an app, there can be only one deployment target. But you can have more than one app in a project, and could have different deployment targets for each. Say you have the older version of your app that works all the way back to iOS 4.3, and a newer version that only works in iOS 7 and later. You could have them both be part of the same project in Xcode and use a different deployment target for each.

Resources