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.
Related
As title, have any idea let widget get main app data?
As I know using App group to save & load the same suite userdefault.
Does have another way to achieve this feature?
Thanks.
AFAIK as you just mentioned the App groups is the way to go when sharing content between your main App and your widget.
Apple is really restrict about user data safety, and don't think there is there any other way to share content without using the app group as we can see on their documentation available here (Sharing Data with Your Containing App)
Something that would try is using a local notification I think this might work to trigger a local notification to your extension and handle the string on the other side :)
More details available here
I would like my App to open for VCards (.vcf format). I know that the type is known as public.vcard and has mime-type text/vcard.
How is this type registered in the info.plist?
I have declared many custom types (UTI) and that works for me, but the VCard is a known format and so far I did not manage to set it up. When I for example airdrop a vcf file, then iOS Contacts shows up, but not the "open with" dialog.
There is a similar question already, but the proposed solution does not work: https://stackoverflow.com/a/16506340/4180386
Some of the types handled by system apps that provide API access to the data (photos, contacts, calendars, etc) seem to only offer the system app as an airdrop destination. Other types work fine and result in the “open with” alert as you pointed out.
I want to send .pdf or image file from my app1 to app2 like instagram hooks. I don't want to show options. I want to send the file directly from app1 to app2 if app2 is installed.
At first I tried using custom URL schemes by modifiying this example. It is good for sending some strings but I couldn't find I way to send files with custom URLs. I've tried to encode file to base64 string and appending to URL. It didn't work. URL becomes broken.
Then I searched for implementing UIDocumentInteractionController Uti as Instagram and WhatsApp does. But I couldn't find any sufficient examples. This is the right way I guess but there isn't much information to go on.
How could I achieve this with the methods mentioned above? (App groups, keychain, pasteboard are not good options for me)
This is very old question, but I think, you tried to find something like this:
If you would like other applications to open your app based on a file type, you can register your document request in the application plist file. This provides a means to associate any file type with your iOS app.
Include the CFBundleDocumentTypes key, which is an array of dictionaries, where each entry defines information about the file type(s) your app supports.
Here are some useful links:
iOS Tips and Tricks: Associate a File Type with your App
How to register file types supported by an iOS app
How To Import and Export App Data Via Email in your iOS App
I have a free version of an app and a paid version. I'd like to give users the option to import their existing data from the free version into the paid version.
Currently the data is stored in Core Data.
I've looked at existing solutions across the internet and SO, the existing solutions suggest making a request from the free application to the paid application using a URL request that contains the data. (e.g. http://mobileorchard.com/lite-to-paid-iphone-application-data-migrations-with-custom-url-handlers/)
So my question is, how is best to implement the solution in Swift:
Is the URL method still the best approach?
Are there any code samples available?
One idea I've had is to convert the entire DB to JSON, then to make a request with the JSON payload and deserialise it into Core Data the other side. Create json string from core data and vice versa?
What I'd do is set up an app group that both apps can access. Put your data in the app group folder and access it from both versions. You don't need to copy it, just leave it where it is.
To do this:
Set up an app group in the "App Groups" section of the target settings in Xcode. Use the same app group for both versions.
Find the location of the app group folder with:
NSURL *groupURL = [[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:
#"GROUP_NAME_HERE"];
Or in Swift:
//swift
let groupURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groupIdentifier")
Modify your Core Data setup code to put the persistent store file in the directory you found in the previous step.
Since you have existing apps, you probably want to move the existing data into the new app group directory. You'd do this by using migratePersistentStore:toURL:options:withType:error: to move the existing store to the new location from step 2.
At this point both apps can read and write the same directory. When people buy the paid app, the data is literally already there for it.
The keyword is Inter-App Communication. One straightforward way would be to write a URL scheme handler.
From: iPhone OS Programming Guide
Apps communicate only indirectly with other apps on a device. You can
use AirDrop to share files and data with other apps. You can also
define a custom URL scheme so that apps can send information to your
app using URLs.
Note: You can also send files between apps using a
UIDocumentInteractionController object or a document picker. For
information about adding support for a document interaction
controller, see Document Interaction Programming Topics for iOS. For
information about using a document picker to open files, see Document
Picker Programming Guide.
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html
I'm working on adding the ability to use the share button to allow users to save files for use with my main application. Multiple file types (image, video, audio, pdf, etc) need to be supported.
A general use case would be:
The user takes a picture with the standard Camera app or audio recording using the Voice Memos app.
User clicks the Share button and selects my extension from the share list.
Dialog opens up giving the user to opportunity to give a description for the file.
File is saved to where my main app (the containing app) can later access and process it.
I've been able to get to the point where I am prompted to share the file, but I have not been able to find a location to successfully save to that my main app can later read from. Is this even possible? Is there a better way to handle this scenario?
I am currently doing this using Xamarin so debugging is not supported (and logging is minimal). If someone has an answer in Objective C, that would at least help point me in the right direction.
There are a few things that you need to do.
First, your app and your app extension should belong to the same app group:
https://developer.apple.com/library/prerelease/ios/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19
Then you can access the shared storage with something like this:
var groupUrl = NSFileManager.DefaultManager.GetContainerUrl ("stackoverflow.com.mygroup")
Now you can access files in the directory pointed by groupUrl.
Xamarin's guide to creating Share extensions for iOS: http://developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/