fertjh.blogg.se

Didselectpost swift share extension share text
Didselectpost swift share extension share text











Didselectpost swift share extension share text code#

In here, we’ll add the code needed to extract the url and user entered text for our share. This is a delegate method that gets called when the user taps the “Post” button in the share dialog. You’ll see Xcode stubs out a few methods for us, but to keep this example focused, the only method I’ll work in for this example is didSelectPost. Now that we’re configured, lets get into the code and open up ShareViewController.swift.

didselectpost swift share extension share text didselectpost swift share extension share text

The final result of the NSExtensionKey node in the file should look like this: NSExtensionNSExtensionAttributesNSExtensionActivationRuleNSExtensionActivationSupportsWebURLWithMaxCount1NSExtensionPointNamecom.share-servicesNSExtensionMainStoryboardMainInterface This lets the OS know that we’ll be looking for a web url in our controller. We need to change NSExtensionActivationRule to a dictionary and add NSExtensionActivationSupportsWebURLWithMaxCount as a Number with the value 1. If you right click on it in the Project Navigator, and select Open As, Source Code, we can it in its XML form. istįirst thing’s first, lets get our extension configured to share URLs by opening up the ist file and making a few changes. In this example, we’ll ignore the MainInterface.storyboard file as we’re more interested in simply getting the url from Safari to share. If you inspect that folder you should see three files: Click on the More button to the right of the other share icons and turn on the switch for your extension & then select Done. On the first run, you will need to add your extension to the share sheet. Xcode creates a target and a folder of files which you’ll see in the Project Navigator. Once the extension starts running, select a photo and tap on the Share button. If you have that working, then we’re good to move on. If you tap on your app, a native share dialog should appear. The Action Sheet should appear and your app should be amongst the sharing options. Now run the app in Xcode, open a website in Safari and tap the Share icon on the bottom. Remember, app extensions must be distributed with your main app. Next, you’ll need to name it, and then make sure it belongs to your correct project and embedded in your main target. After struggling and digging, here is a working example.Ĭreate a new app extension target by going go File, New, Target in the Xcode menu, then in the left panel select Application Extension and select Share in the right pane. My objective was to let the user share a web page URL with my own custom app. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.ĮxtensionContext?.While trying to get an iOS 8 Share Extension working in the new Swift language, I ran into some issues due to lack of examples and incomplete documentation. Inform the host that we're done, so it un-blocks its UI. Let task = session.dataTask(with: request! as URLRequest) Let request = urlRequestWithImage(image: attachedImage, text: contentText) Let session = URLSession(configuration: sessionConfig) SessionConfig.sharedContainerIdentifier = "group.CreateDaily" Extensions aren't allowed their own cache disk space. Let sessionConfig = URLSessionConfiguration.background(withIdentifier: configName) Do the upload of contentText and/or NSExtensionContext attachments. This is called after the user selects Post.

didselectpost swift share extension share text

This is my code that initiates the background upload: let sc_uploadURL = "" // The share extension works fine and it shows up in Preview, once I run it: I'm still testing this so any requests will be sent to. I created an macOS ShareExtension which I want to use to upload pictures.











Didselectpost swift share extension share text