How to create and use a custom UIPasteboard in Swift - ios

Need to copy a text to pasteboard but not general one, apple docs doesn't refer how to use a created one

Custom UIPasteboard can created by
UIPasteboard(name: <UIPasteboard.Name>, create: <Bool>)
Here the name parameter will be name of the pasteboard through which you can retrieve it later and the create parameter takes a bool that tells to create one or not if a pasteboard does not exist by that name.
For more details refer to- pasteboardWithName:create:

Related

How to get Object ID for dynamically created Label?

How to get Object ID for dynamically created Label?? As I have to translate Label text for other languages.
Object ID is created by the interface builder and interface builder use it internally, there is no such property of UIView which gives you object id. Hence you can't access it via code (dynamically) regardless whether view is created on storyboard or at run time.
We can translate text from app using String file. In string file we can store strings we want to translate.
Ex:
Localizable.string(Hindi)
"translate" = "अनुवाद करना";
Localizable.string(English)
"translate" = "translate"
As we run app, app automatically store selected language translations from file.
Ex.[[Localisator sharedInstance] setLanguage:[language];

How to suggest my application in the list for save pdfs?

I am working on an application which I used pdfkit to implement that, and it shows and save pdf files.
My problem is that when I receive a pdf file in my email and then I want to save that pdf file in that application, when I click on save button it suggests this page to me but my application is not in the list. How can I make sure that my application also comes in this list as a suggested app?
Refer this link:
https://developer.apple.com/library/content/qa/qa1587/_index.html.
You need to register the document types that your application can open with iOS. To do this you need to add a document type to your app’s Info.plist for each document type that your app can open. Additionally if any of the document types are not known by iOS, you will need to provide an Uniform Type Identifier (UTI) for that document type.
Adding A Document Type:
To add the document type do the following:
In your Xcode project, select the target you want to add the document type to.
1.Select the Info tab.
2.Click on the disclosure button for Document Types to open the document types.
3.Click the “+” button.
In the newly created document type :
4.Type the name of the document type.
5.In the “Types” section fill in the UTI for the new type.
6.Provide an icon for the document.
7.Click the disclosure triangle to open Additional document type properties.
8.Click in the table to add a new key and value.
9.For the key value type: CFBundleTypeRole.
10.For the value type: Editor.
11.Click the + button to add another key/value pair.
12.For the key value type: LSHandlerRank.
13.For the value type: Owner.
Adding A Custom UTI:
If the document type you are adding is a custom document type, or a document type that iOS does not already know about, you will need to define the UTI for the document type. To add a new UTI do the following:
In your Xcode project select the target you want to add the new UTI to.
Select the Info tab.
1.Click on the disclosure button for Exported UTIs.
2.Click the “+” button.
3.Select “Add Exported UTI”.
4.In the Description field, fill in a description of the UTI.
5.In the Identifier field, fill in the identifier for the UTI.
6.In the Conforms To field fill in the list of UTIs that this new UTI conforms to.
7.Toggle the “Additional exported UTI properties” disclosure triangle to open up a table where you can add some additional information.
8.Click in the empty table and a list of items that can be added to the table will be displayed.
9.Type in “UTTypeTagSpecification”.
10.Set the type to Dictionary.
11.Click the disclosure triangle to open it, and click the + button in the table row to add an entry.
12.For the “New item” change the name to “public.filename-extension”.
13.For the type of the item change it to “Array”.
14.Toggle open the item you just added and click the + button in the table row.
15.For item 0 change the “value” to the file extension of your document. For example, txt, pdf, docx, etc.
The easiest way to test your custom document type is to email your custom file to your iOS device. Navigate to the email and ensure that the attachment is there. Tap and hold the document attachment icon. This should open a popover on the iPad, or an action sheet on the iPhone, that shows all of the apps that open your document type. Your app should show up in the list. Tap your app icon and your app should launch and receive the document from the email.
You need to create Action Extension.
Take a look at PSPDFKit's article.

UIActivityViewController Not Displaying Expected AirDrop Option for Custom File Type in My App

So the typical way you share a document via UIActivityViewController is code similar to this:
let ac = UIActivityViewController(activityItems: [obj], applicationActivities: nil)
ac.popoverPresentationController?.sourceView = self.view
self.navigationController?.presentViewController(ac, animated: true, completion: nil)
The issue is I'm not sure what kind of class obj is supposed to be. I have a file that works with the eDrawings iOS app from SolidWorks. I know that it works because I was able to AirDrop it from my laptop and it got copied over and opened correctly on my iPad that has the eDrawings app on it.
If you take a look in a mail message that contains the eDrawings supported file types on said iPad, you can see that it provides the expected option in the popover.
My question is, how can I do the same thing? Mail must be doing it generically without knowing the UTI explicitly, so what should my obj field be in the example code I provided above in order to get my activity view controller to display the same option as in Mail? I've tried using an NSURL both with the file downloaded locally as well as a URL on the web. Neither of those work. I would think I should just use an NSData, but at that point, how would the activity view controller know what type it is implicitly like it does in Mail?
Any ideas?
Try to think of "Activity View" as the place in iOS (a file-free environment) where developers can allow their files to escape the device.
The API says give me a list and I'll fill the view. The docs have the details, hidden in the enum descriptions...
for AirDrop
When using this service, you can provide NSString, NSAttributedString, UIImage, ALAsset, and NSURL objects as data for the activity items. You may also specify NSURL objects whose contents use the assets-library scheme. You may also provide NSArray or NSDictionary objects that contain the listed data types.
https://developer.apple.com/documentation/uikit/uiactivity/activitytype/1620665-airdrop
for Mail
When using this service, you can provide NSString and UIImage objects and NSURL objects pointing to local files as data for the activity items.
To specify an NSData object, you must implement the UIActivityItemSource protocol, return the data object in activityViewController(:itemForActivityType:), and return the data object’s UTI in activityViewController(:dataTypeIdentifierForActivityType:). Also, you may need to register the appropriate mapping so that the MIME type can be determined.
https://developer.apple.com/documentation/uikit/uiactivity/activitytype/1620669-mail
Try implementing UIActivityItemSource in your obj class.

How to save webpages and open it after clicking?

enter image description here
Attached is screenshot for my view controller. When users search on internet, how do I realize these functions?
save current web page ( maybe go to another view controller after clicking "save")
my idea is to save on a table view, with a brief title
after clicking the title, shows contents of the whole page saved.
if users reply emails on some website with attachments, they can also save the attachments (word, pdf,etc) in the app.
I initialized the web view with google. The problem is the page to be saved can be any NSURL, I have no idea how to do that.
Or you can advise some way totally different, as long as I can realize these functions.
For future reference you should include some code... but anyway, I would just set the NSURL as a string of each webpage in NSUserDefaults then call the main applications open URL method.
Like...
NSUserDefaults.standardUserDefaults.setObject("YourURL" forKey: "URLKey")
NSUserDefaults.standardUserDefaults.synchronize()
Then retrieve it like...
if let urlString = NSUserDefaults.standardUserDefaults.objectForKey("URLKey") {
let url = NSURL(string: urlString)
UIApplicationSharedApplication.openURL(url)
}
I wrote this code off the top of my head so it might need some tweaking but I hope it helps!
If you want the user to save many webpages, you should not use NSUserDefaults to achieve it. You should use something called CoreData. This is because NSUserDefaults can only save one url at a time. If you want to save another, you need another key to do so.
Here is basically what you need to do. You create a new Core Data Model file (.xcdatamodeld). Add an entity called SavedUrls. Add a property to that entity called urlString. Then generate a NSManagedObject subclass.
To save data, get the managed object context from the App Delegate. Create a new instance of SavedUrls using the inherited initializer. And change the property to the url to be saved. Then just call save on the context.
To get data back, get the managed object context and create an NSFetchRequest to fetch from the database.
Learn more here:
https://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial

Umbraco - Automatically sync the Content Node Name with a doc type property

Am using Umbraco 4.11.10
Is there a standard way to create a document type property which when updated, automatically syncs with the content node name?
I know this can be done in the Properties section in the Name field but that field cannot be moved from the properties tab and it is a little out of the way - users get confused.
How is this usually done?
Wing
There are some special use umbraco field aliases. One is umbracoUrlName which will override the page url - just add it to your doctype and put it in whichever tab you want to change the url from.
EDIT
Another option would be to create a custom data type and use it to create a field that overwrites the node name. Add a text field as the UI of the custom data type; add an event that is fired whrn the textbox changes and update the name.
http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties
// Get the document by its ID
Document doc = new Document(node.Id);
// Get the properties you wish to modify by it's alias and set their value
// the value is saved in the database instantly!
doc.getProperty("name").Value = <input textbox value?;
// After modifying the document, prepare it for publishing
User author = User.GetUser(0);
doc.Publish(author);
// Tell umbraco to publish the document so the updated properties are visible on website
umbraco.library.UpdateDocumentCache(doc.Id);

Resources