Role of framework in between Extension and App in ios - ios

I'm bit confused about the concepts of Extension in ios. After going through some tutorials I still have doubt how an app and an extension in ios communicate each other, does this has to do anything with Framework. If Yes, why we are adding Frameworks...
Hoping for a response, Thanks

App extensions are not stand alone apps. They are providing extended functionality of the app (which can be accessed from main app, called the host app) that is meant to be efficient and focused towards a single task.
For example, Today widget in iPhone is an extension. We can create a today widget for an iOS app which is an extension of the existing iOS app. For example, let us consider an app which shows current weather in detail. Then you can create an extension for this app, to show only current temperature without much detail in a widget.
The extension uses the data which is shared between both the main app and the extension. Embedded framework is a technique to share same code between two targets. You can share data using NSUserdefaults and app group concept.

Related

How updating dynamic framework will affect App Store build

I have an app on the App Store and I have to create another app. This other app has some of the same functionalities as the first app. So I wanted to create a framework to put the common code in and use it inside the apps. Unfortunately, this framework has to change to add more features and improvements.
I saw that dynamic libraries can update the library code without any change to an app already pushed to the App Store. But this is reserved for Apple. Also, since iOS 8, we can create a dynamic framework which includes dynamic libraries. So is it possible to have the same, meaning if I update my dynamic framework, it also updates the app without having to push to the App Store again and face app review process?
If not, do you have some clues/recommendation to achieve that?
Dynamic Framework is a bit different from the understanding you have. Please read apple documents in more detail for that.
Currently only way to achieve what you expect is to push code on App Store as hidden, and based on some server API configuration update your content accordingly (Firebase Remote Config is one such good example if security is not that big a concern)

How to pass objects/data between my iOS applications

I have an existing iOS application on the app store, and I am building a new companion app to work with this existing app.
I need to pass objects/data from this new app to my existing app when a certain action is taken. The behaviour I'm looking for is very similar to AirDrop but the data is passed to another app on the same device.
The objects I want to pass locally between apps are simply NSObject's.
As per your comment you wants to share NSObjects between your iOS apps. The best approach would be "Custom URL Schemes". But in this approach you may need to add or re write some parts in your old iOS App as well.
checkout this SO Answer for more info on implementing custom url scheme and history of sharing data between ios apps.
Apple documentation for sharing data is also available.
If your app supports greater than iOS 8 you can also use the new feature called "App Group Functionality"

How to call a method in the parent iPhone app from Today Extension in Swift?

I have just created an Apple Watch extension to my iPhone App and used the following method to update my app data.
// Call the parent application which launches a method to update the app data
WatchViewController.openParentApplication([:],
reply: { (reply, error) -> Void in
self.updateGui() // update the gui when done
})
Is there anything similar for Apple Today Extensions (widgets)? It feels wrong to implement all the client-server communication again for the extension.
Or how do you suggest to update my data (stored in app group throughout iPhone app, WatchKit and Today Extension).
No need to write client-server communication code separate for container app and its extension.
Apple recommends embedded frameworks for the same. You create an embedded framework which can be used across both targets. Place code that will need to be used by both the container app and extension in the framework to avoid code repetition.
And for sharing data between container app and extension, you can use NSUserDefaults through AppGroup.
Please check Apple documentation.

Any iOS 8 app extensions/extension types that work with iPhone's Message app?

While reading on app extensions introduced with iOS 8, I noticed that there are extension types that can work with an iPhone user's images, notes etc. But I was wondering if I can make an action or a share extension that would work with iPhone's Message app as the host app. Is there any resources about it?
Edit: I understand that you need to specify a particular data type for app extensions to work on certain data type. Are text conversations a certain data type/object?
I guess this is a misunderstanding of what Share Extensions are.
You embed a Share Extension into your app to offer services of your app to others. Any app that embeds a Share Sheet and provides data of a type your extension offers to handle can (and will) use your extension.

HealthKit & Today Extensions/Widgets

Has anyone combined these two new features in iOS8 yet? I'm attempting to access HealthKit from a widget. But since the application and extension use two separate App IDs - the widget automatically rejects access to HealthKit. The Notification Center/Today view doesn't display any prompt to allow access. I notice it attempts to because I see an "unbalanced view controller transition" warning in the console, but nothing is displayed.
For a manual fix - the Health app will display the bundle ID with permissions that can be manually changed. However, there's no app icon and the extension is listed as its bundle ID and not listed as its product name. This makes me think this is still something they are working on in the beta.
You could try to access the HealthKit data from your containing app and then share those data with your extension through App Group.
I haven't looked at HealthKit yet, but in another case the App Group feature worked fine for me.
I haven't tried doing this type of combination between those features in my app yet, but while integrating the HealthKit capabilities, I happened to see the following in HealthKit documentations:
Both HealthKit and the Health app are unavailable on iPad. The HealthKit framework cannot be used in an app extension
So I assume a direct way is not available... You can read more here: HealthKit_Framework Documentation
You won't be able to access HealthKit. To quote Apple's App Extension Programming Guide:
Some APIs Are Unavailable to App Extensions
Because of its focused role in the system, an app extension is ineligible to participate in certain activities. An app extension cannot: …
Use any API marked in header files with the NS_EXTENSION_UNAVAILABLE macro, or similar unavailability macro, or any API in an unavailable framework
For example, in iOS 8.0, the HealthKit framework and EventKit UI framework are unavailable to app extensions.
[emphasis added.]

Resources