What are these copy to app buttons called in swift? - ios

What do you call these copy to app buttons and how to implement them with your own app? Copy to Spark, Viber etc.

They are action / share extensions exposed by other applications to handle a text / photo / url share from any app , you can find them under File->New->Target

That view is a UIActivityViewController.
Those buttons are activities.
The controller is created and then the information is passed in. The activities shown are determined by the type of info passed in (photos, text, url, etc...) and the apps that have registered to handle that type of info.
Have a google for UIActivityViewController to see how you can implement those activities for your own app.

Related

How can I open my app directly from the iOS Share Sheet?

Update: don't have time yet to test provided answer, but will keep this answer updated as I try different things.
In the iOS 14 Simulator, when I open the share sheet and click their Share Target, the Apple News app is launched immediately and they check if the shared URL has been added to their index.
My question is how are they launching their app immediately without any user interaction?
A gif is worth about 100,000 words: https://giphy.com/gifs/HPzTNyWGDDMVwASQ9z
I would imagine it may be some combination of registering a Universal Link and then programmatically triggering that from the Share Extension View Controller, but I’m wondering if anyone has any better ideas.
A couple of other places I've asked:
Swift Subreddit
iOS Programming Subreddit
This is just an open URL call to a news app. Prior to iOS 14, it was named as copy to app name.
To achieve this you need to specify the supported document type for your application in plist using key CFBundleDocumentTypes.
Refer to apple documentation for more info:
https://help.apple.com/xcode/mac/current/#/devddd273fdd
There is a change in share sheet option listings.
case 1: When your application doesn't support any kind of extension. And have supported document add to plist. Your application will appear in the share sheet for supporting documents. On tap, your application gets an OpenURL call with the URL of the document shared.
case 2: Your application supports share extension or action extension, then your open URL call option for your application will not appear in the share sheet. if the share extension and action extension activation predicate are not satisfied and the document shared is supported by your application that option will appear the same as case 1. (Summary: if share extension or action extension is listed in share sheet then open URL option will not be listed.)
Note: Limitation of openURL call is, it supports only a single URL. For example, you are sharing multiple files, your application OpenURL option will appear. But on tap, your application will receive only one URL.
If your requirement is sharing only a single URL and your application doesn't have a share extension and action extension. Then key CFBundleDocumentTypes is your friend.

Passing data between an iOS app on different devices

I’m looking for the best and efficient way to pass a Nested Array [[String]], from my app to the same app on another iPhone.
If let say for example, I have this Array saved on my app:
let array = [[“John”, “27”, “First”, “Castle”],[“Tom”, “25”, “Second”, “Boat”]]
I want to add a Share Button on my App that will allow this array to be shared via Bluetooth/Airdrop/Any Convenient Way between 2 iPhones.
Ideally click share, via airdrop, other user click accepts and clicks open with the app. And data is loaded. What is the best approach In order to achieve this. I looked at Share Extension and UIActivityViewController but can’t see what are the differences about them and what is best for my case to simply send data and receive data from and to my app.
Based on what you have said,
You could just use the UIActivityViewController to export your data to AirDrop (or etc)
and using the exported UTI, your app could open it once it detected.
for Sharing, you will have to use a custom data format (or file) and you can refer to this post, Sending custom data via UIActivityViewController
and for reading your custom file, here is a good tutorial of how to implement the Exported UTI https://www.raywenderlich.com/8413525-universal-type-identifiers-tutorial-for-ios-importing-and-exporting-app-data
Cheers,
Kel
One option (and probably the easiest) is to use iCloud, specifically the NSUbiquitousKeyValueStore.
More information here :
https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore
use UIActivityViewController to export your data using AirDrop. You can read the same in your app on other phone when it detects the exported UTI.

How to share a link of my app from app in iOS(swiftui)?

I want to have a button in my app that will allow the user to send a link of the same app via message, whatsApp, or whatever.
Is that possible ? I haven't found any solution for this.
You can use UIActivityViewController to display the standard share dialog. Since this is a UIViewController you will need to wrap it in a UIViewControllerRepresentable to use it with SwiftUI.
The item you share will be a URL instance that contains the App Store link to your app.

Other apps not allowed in UIActivityViewController?

I'm working on an iOS app in Objective-C and I'm currently trying to make a sharing extension with a UIActivityViewController.
I understand that there is an enum of activity that I can individually exclude from the UIActivityViewController with a property of type NSArray called excludedActivityTypes.
How can I also exclude other apps (such as Pinterest or LinkedIn) that the user can manually add/activate/disable from the panel that shows when you hit the "Other" button in the UIActivityViewController ?
Thank you in advance.
How can I also exclude other apps (such as Pinterest or LinkedIn) that the user can manually add/activate/disable from the panel
You cannot. Of course you could try going to the user's house and pinning his arms behind his back, but, short of that, you are not in charge of what the user does.

iOS 8: options for presenting Action Extensions to users?

After reading the Apple documentation on extensions, it's not clear how Action Extensions get presented to users. The docs mention the Bing translate use case where actions are presented after users tap the Share button. But what if an app, say a chat app, doesn't have a share button? Another example is if the calling app (not the containing app of the extension) presents an option to invoke an Action Extension.
Are these the only two options? In other words, if an app lacks a Share button and doesn't integrate your extension, there's no way to present an Action Extension?
That is correct. Actions are always initiated by the user, and always from system-provided UI.
Extensions are presented as a possible in a UIActivityViewController. The host app provides the UIActivityViewController with the data context. If your extension adheres to this context, it will be available in the list.
If someone writes an app without the UIActivityViewController then they won't be able to use your extension.
May be help you.
Apple provides sample code for ImageInverter: Creating Action Extensions
There are concept for Action Extensions.

Resources