UIInputViewController - Disable Keys Based on User Input in Container App - ios

So, let's say I have a container app and an extension to that app for a custom keyboard. Let's say that custom keyboard has, by default 5 keys. Doesn't matter what those keys are.
Now, I want the user to be able to DISABLE any of the 5 keys in the container app. If disabled in the container app, the keys should appear red and disabled in the keyboard.
My question is: How do I load the user preferences/serialized data from the container app, into the UIInputViewController?
If anyone could help with steps necessary to make this happen, or provide a link to a tutorial (I can't seem to find one), it would be much appreciated.

So I finally figured it out.
Here are the basic steps.
1) Create a Shared Group. This link provides step by step instructions on how to do that: https://stackoverflow.com/a/29051138/1152868. I had initially implemented these steps but I was still unable to access the shared directory (outlined in https://stackoverflow.com/a/26050187/1152868) from the extension. Turns out you have to add the entitlements file to both the container app AND the extension target. That was the biggie for me.
2) Once you confirm open access across your container app and the extension, you can share data between em. I referred to this tutorial for sharing: http://www.atomicbird.com/blog/sharing-with-app-extensions. You have two options: using a shared file directory or using a shared NSUserDefaults domain. In my app, I was saving and loading data with NSCoding. But, I experienced issues with unarchiving the data in the extension, so I decided to save to NSUserDefaults instead (the data I need in the extension can be formatted as a simple dictionary, so it was easy enough).
Using Shared Groups and NSUserDefaults, I am now able to save and load data from the container app to the extension!

Related

Document Renaming with UIDocumentBrowserViewController

I am using the "new way" of storing documents (iOS 11+) using UIDocumentBrowserViewController. No need for iCloud API, Entitlements etc. -- just works (under control of the separate Document Browser process).
However, I haven't figured out how to rename (i.e. move) a document programmatically this way, at least within iCloud. The standard "url.setResourceValues()" does work just fine on the local filesystem, but renders in 513/not permitted in iCloud. Also all the former ways of doing it (using full set of iCloud capabilities & entitlements, using complex FileCoordinator orchestration etc.) don't work either when the created document actually is controlled through the document browser.
I couldn't find any reasonable documentation or example on how to use the UIDocumentBrowser to also move a document under it's (and somewhat my) control. There is the UIDocumentBrowserImportModeMove mode that might do what I need, however I have no clue how to programmatically initiate that on a given UIDocument.
Has anyone already made experiences to do it this way?
Thanks, habitoti
There is no API to move a document that was returned to you by the document browser after the user picked it. You should file a bug with Apple to get one.
If this is inside your iCloud container, you can use the iCloud entitlements and -[NSFileManager URLForUbiquityContainerIdentifier:] to get sandbox access to your container and do whatever you want inside with NSFileManager; but that won't work in iCloud outside of your container or in other file providers (Dropbox...).

iOS - import file from another app into my app

I want to import a document from another app into my app like it's done in MS Outlook iOS app when you click the paperclip in an email. Then you get a list of apps (dropbox, google drive etc) + recent documents and you can select a document.
How is this done / do I need to use the app-extensions for this ?
thanks
Frank van Vliet
this is the scope of App Extensions. To add an App Extension to your Project you have to navigate to File -> New -> Target and the App Extension you are looking for is called Document Provider. Please first check the WWDC Video on best practice for App Extensions and the App Extension Programming Guide. It will help you to develop the understanding of this Feature.
EDIT:
Maybe I set you on the wrong track, but within the App Extension Programming Guide you could have found the answer to your Question. I'm using Xcode 7.0 Beta 4, but most of the following screenshots should look exactly the same in Xcode 6.*. First of all I started a new SingleView-Application written in Swift and added the Document-Provider Extension as a target to the Project as outlined above.
After building the application with the new Document Provider target I ended up starring confused onto the Share-Menu realising that we talked at cross purposes. The Documentation on this target is slightly muddled but after a while of testing and searching I realised that the thing you are looking for is the Document Picker, not the Document Provider. On this Page you can find the Relevant Chapter: Accessing Documents Link, where you can get examples for the Document Picker.
Since this will hopefully solve your Problem, I would like to shortly refer to the Document Provider and the overvalue it could add to your Application.
The Document Provider extension consists of two separate parts: the Document
Picker View Controller extension and the File Provider extension. The Document Picker View Controller extension provides your document provider’s user interface. The system displays this interface when the host app presents a document picker view controller for your document provider. This interface should let users browse through and select documents and destinations from inside your document provider. This extension can also perform basic import and export operations without any additional support.
from the App Extension Programming Guide as mentioned above
So the Document Provider is kind of an Import Feature as seen from another app. If you would implement a Document Provider Target for your Application, other Apps can access designated data. For example you could attach Files from your App to an E-Mail (left screenshot) or Open a File in Pages (right Screenshot).
When working with Files, this could be a nice feature for your users.
Also I would recommend using either a Share or a Action Extension.
Share extensions give users a convenient way to share content with other entities, such as social sharing websites or upload services. For example, in an app that includes a Share button, users can choose a Share extension that represents a social sharing website and then use it to post a comment or other content.
That doesn't sound exactly like the thing you want to achieve, but at the moment even Apple uses the Share Extension for all kinds of things.
An Action extension helps users view or transform content originating in a host app. For example, an Action extension might help users edit an image in a document that they’re viewing in a text editor. Another type of Action extension might let users view a selected item in a different way, such as viewing an image in a different format or reading text in a different language.
You said you want to import a document from another app into your app. This sounds handy. Lets assume a user opens a Document "loremIpsum.txt" in the iCloudDrive Application and wants to share it to your new app.
Now, you have to write the code to handle imported files when opened by the Document Picker, you could reuse this code to easily add a Action Extension to the Share-/Action-Menu. I hope this will help you and solves more than one problem.
Best regards
cr0ss

iOS App groups - shared CoreData fails to open

I have an app with a CoreData database and access it using UIManagedDocument.
To share the data with the Watchkit app, I'm moving the database to a shared App Group.
The store is created correctly it seems, but after that it often becomes impossible to access it: the UIManagedDocument keeps trying to reconfigure the store, and NSFileManager doesn't find the file (with fileExistsAtPath).
The problem is in the database location - if I save it in the documents directory instead of the shared Group, it works without trouble. It's also not a problem of accessing it from both apps, even if I don't open the watch app at all the problem appears. The group is also working correctly for sharing NSUserDefaults.
Did anyone see similar problems? Is there any locking mechanism that I need to deal with in a specific way?
Any help will be greatly appreciated, I've been struggling a lot with this issue!
After a lot of searching, I found that the storeURL would change (randomly) between these two:
file:///var/mobile/...
file:///private/var/mobile/...
I used URLByResolvingSymlinksInPath on the URL as specified in the following answer, and incredibly, it fixed it:
What does the /private prefix on an iOS file path indicate?
I'm assuming this is a system bug with the App Group paths... it seems that the different paths were causing the persistentStoreCoordinator to try to reopen the store when it was already open.

Read CoreData in Today Widget in Swift or Objective-C

I really need some simple code for me how to read CoreData in TodayWidget
This steps I made:
Create new project with using CoreData (in AppDelegate)
Make an Entity in CoreData model and some Attributes like a name or date
in ViewController of App fill name and date with one record like "Martin" "10/11"
And Now I need to read this name in TodayViewController
Please really post here just some simple code from it, or how to edit AppDelegate for using appgroup ...
Thanks !
Widgets have to be able to read the data in their code. In order to do this, you need to setup your CoreData files to be located in a 'group' folder in your project (You can set your CoreData Stack to relocate it's files in this folder). Then you'll configure a CoreData Stack in your extension that points to the same files. These group folders are folders that can be access across multiple targets/applications that have permissions for the group.
I will point out that it's far easier to use and sync NSUserDefaults across a widget and it's appropriate application than it is CoreData.
You'll want to read Apple's documentation about sharing extension data below:
Apple docs
Note the following section:
Sharing Data with Your Containing App
Even though an app extension bundle is nested within its containing
app’s bundle, the running app extension and containing app have no
direct access to each other’s containers.
BACKGROUND
To learn about containers, read About the iOS File System in File
System Programming Guide.
You can, however, enable data sharing. For example, you might want to
allow your app extension and its containing app to share a single
large set of data, such as prerendered assets.

Can I bundle /package two apps into one?

I have two apps. The first one checks for passwords and credentials and if all is well, then launches the second app. Can I bundle/package the two apps into one? The intent is to present the whole thing as a single app to the Appstore.
Is this approach supported for iOS and accepted by Apple?
How about framework? Although I think a customised framework is not supported for iOS which is of no use to my case.
Any hints or code samples as how to achieve this (if at all possible) is very much appreciated.
Thank you for your help.
You can't bundle two apps, but you can write your own framework that checks credentials and add that to your app. From the information you give, I can't see the reason why you need to put credential checking into an extra framework. Can't you do the check inside your app?
I suggest you to create a library for Login (where you can check the credentials of user once authentication is success use protocols to send the information of user or the status (success or failure) to the main app where your total application is presented). Creating a library (.a and .h) file is easy here you can't use Xib files and images for this you need to create a new bundle where all your Xib's and images are added for library purpose. In other case you can use images as a base64 string. So your total app is now splitter into 2 parts 1. Library for Login 2.All other features. If you need more information on this please let me know.
Hope this will give you an idea and helpful

Resources