IOS Action Extension Sample Code - ios

i am new to IOS development ,IOS 8 have app extension feature, i have gone through Apple document ,i got some idea what is app extension but i want do sample non UI action extension app example. i tried ui based extension app ,it's working fine.and also i tried non ui base app but it not working. please can any one explain non ui extension with sample code.
just take simple case Host app will send x and y values to extension , extension need to receive that two values and do some manipulation in extension app and send result to host app and host need to display on ui.

Related

Safari extension iOS - messaging from app to extension

With iOS 15, Apple had made it possible to create Safari extension for iOS as well.
I'm currently in the process of bringing an existing macOS Safari extension to iOS.
My problem is that there doesn't seem to be the option to send a message from the host app to the extension. It is possible to answer a request from the extension through the
beginRequest(with:) function. However, I actively need to send a message to the extension after an user action. In macOS, this can be done through the dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:) function as described here: https://developer.apple.com/documentation/safariservices/safari_web_extensions/messaging_between_the_app_and_javascript_in_a_safari_web_extension. This function is unfortunately not available for iOS.
Would greatly appreciate any ideas for solving this problem.
You can enable permission ["nativeMessaging"] in manifest file of the safari extension
Use appGroup to store data between the extension and your application.
In SafariWebExtensionHandler, you can response appGroup Data to the message called from any extension javascript file.

How to get the iOS Camera suggest my app when snapping a QR code

I want the Camera App that comes with an iPhone to recommend a QR code be opened up in my app. My first question is, if two or more apps register the same universal link, which app gets suggested.
For instance I removed one app that kept on being recommended. Then suddenly another app starts getting recommended. How does a user or developer control this.
Have a look at Apple's guide for implementing Universal Links. In short, your website must upload a JSON file at a specific location that tells iOS which apps can be associated with the website domain. Here is an example file used by the NBC app.

Role of framework in between Extension and App in 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.

XML parser recommendation for WatchKit extension

I am building an app that on hourly basis downloads/parses an XML file from internet and displays a specific field on a apple watch / watchkit complication.
My current app within ExtensionDelegate parses (in Swift2 using NSXMLParser) which works well on simulator but does not work on physical device (I assume it times out).
How do you parse in watchkit extension? use any add-ons?

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.

Resources