iOS share extension, configurationItems (tableView)

Related searches

please barer with me that I am completely new to swift and iOS..

I'm trying to make a "team select" on my share extension. Ideally I want to be able to tap the "Team" footer and select multiple teams from a table view, and at last share/post to the selected teams.

I have been following a tutorial from 2016, but I think it is outdated by now unfortunately, and I haven't been able to find one similar that is up to date. (if you know one please link)

I have created a TeamTableViewController.swift (UITableViewController) with a hardcoded teamList which I hope to populate in the share extension.

my UITableViewController file looks like this:

import UIKit

protocol TeamViewProtocol {
  func sendingViewController(viewController: TeamTableViewController, sentItem: String)
}

class TeamTableViewController: UITableViewController {

  var teamList: [String] = ["Team 1", "Team 2", "Team 3", "Team 4", "Team 5"]
  var delegate: TeamViewProtocol?

    override func viewDidLoad() {
        super.viewDidLoad()

        self.clearsSelectionOnViewWillAppear = false
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
      return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.teamList.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TeamCell", for: indexPath) 

        cell.textLabel!.text = self.teamList[indexPath.item]

        return cell
    }

}

My ShareViewController filer looks like this:

import UIKit
import Social

class ShareViewController: SLComposeServiceViewController, TeamViewProtocol {

  var item: SLComposeSheetConfigurationItem!
  var teamPickerVC: TeamTableViewController!

    override func isContentValid() -> Bool {
        // Do validation of contentText and/or NSExtensionContext attachments here
        return true
    }

    override func didSelectPost() {
        // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.

        // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
        self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
    }

  override func configurationItems() -> [Any]! {
    self.item = SLComposeSheetConfigurationItem()

    self.item.title = "Team"
    self.item.value = "None"

    self.item.tapHandler = {
      self.teamPickerVC = TeamTableViewController()
      self.pushConfigurationViewController(self.teamPickerVC)
    }

    return [self.item]
  }

  func sendingViewController(viewController: TeamTableViewController, sentItem: String) {
    self.item.value = sentItem
    self.popConfigurationViewController()
  }

}

When I tap the extension window footer "Team" the entire extension dismisses with no error message. If however, I set the hard coded teamList array to an empty array, then the extensions does not crash/dismiss but instead shows the table view with empty rows.

What am I missing in order for my hard coded teams to show as cell/lines/rows? in the table view?

You should return the proper number of sections or can remove that method, so it will take the default value of numerOfSections as 1

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
  return 1
}

Hope it helps

App Extension Programming Guide: Share, Building a share extension in iOS with Swift programming language is pretty design by adding Configuration Items at the bottom of the share sheet. Hence, running the app will enable you to see the table view of dummy� By default, the standard compose view controller (SLComposeServiceViewController) displays your configuration items in a table view at the bottom of the sharing UI. A Share extension uses the configurationItems property of the SLComposeServiceViewController class to return an array of SLComposeSheetConfigurationItem instances, each of which identifies a type of configuration the user can make. When a user taps a configuration item, the item can display a custom view controller that lets the

After a lot of trial and error. I finally found a forum post about the correct implementation of the tableView function that calls with the argument cellForRowAt

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  var cell = tableView.dequeueReusableCell(withIdentifier: "TeamCell")

  if cell == nil {
    cell = UITableViewCell(style: .default, reuseIdentifier: "TeamCell")
  }

  cell!.textLabel!.text = self.teamList[indexPath.item]
  return cell!
}

This was not easy to debug, and there were no error or exceptions printed.

Steps to Build Share Extension in iOS Using Swift 4.0, Creating a Share Extension is very easy in XCode! Just navigate to File -> New - > Target and under the iOS tab, click “Share Extension” Configuration items are created in the Share View Controller's If you are unfamiliar with creating Table Views in Swift, check out Creating a Simple Table View in Swift� 3rd Apr '15. 7. Share extensions, introduced in iOS 8, give users an easy and convenient way to share content with other entities, such as social sharing websites or upload services. Previously, sharing content usually entailed switching from one app to another, for example, while surfing in Safari, if you wanted to share a URL, you would copy it, switch to the app you wanted to save or share it in, perform the action and then resume surfing in Safari.

You also have to implement the didSelectRowAt delegate for the tableView to be able to send the selected item back to the main view.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let selectedItem = self.teamList[indexPath.item]
    delegate?.sendingViewController(viewController: self, sentItem: selectedItem)
    self.navigationController?.popViewController(animated: true)
}

Create a Custom Share Extension in Swift – Talk Dev Design, Under the iOS tab select Share Extension and press Next. to optionally supply configuration items (the cells in the bottom of the share sheet) when tapping on the configuration cell it pushes to a new view with a tableview. For share extensions, the system-provided composition view is familiar and provides a consistent sharing experience throughout the system. Use it whenever possible. For action extensions, include your app name, or design an interface that’s recognizable and feels like a natural extension of your app.

How-to Build an iOS Share Extension in Swift, The main challenge here is that I wanted my share extension to be able to create or Lastly the configurationItems() function is there to enable us to post our info to a specific object. As you might have guessed in our tableview we can select the note we want to Detecting Internet Access on iOS 12+. It looks like that option was removed (or never made it to a public release). Anyway, from reading the description, it sounds like you just need to create a share extension, and change the ShareViewController's superclass from SLComposeServiceViewController to UIViewController, and get rid of the isContentValid, didSelectPost, and configurationItems stub methods in the class definition.

Making a Share Extension that accepts text and URLs in , Just navigate to File -> New -> Target and under the iOS tab, click “Share Extension” Then name your Share Extension. (It is important to note that the name you give your Share Extension in this part is exactly what the user will see when sharing an item) This will create a new Share Extension target with a ShareExtensionViewController that looks like the following.

Under the iOS tab select Share Extension and press Next. Give it a name; I opted for the simple “ShareExtension”. It will ask if you’d like to activate the scheme. This means when you run the

Comments
  • I don't understand what you want to achieve: Do you want to display a table view over the extension, select rows there, and then dismiss the table view and be back at your share extension so that you can post to the selected entries? If so, this is maybe not the best way to do it. Apple's docs say Avoid placing modal views above your extension. Extensions are displayed within a modal view by default. While an alert might make sense above an extension, avoid layering additional modal views.
  • As I read their "Apple way of doing things" docs, I feel quite confident that I follow that convention. I'm not trying to launch a new layer on top of the share extension, I'm trying to populate the configurationItems with a table view with options. hundreds of apps are doing this: example here: github.com/couchbaselabs/mini-hacks/tree/master/… Which were this initial tutorial i was following, however the code is not up to date with swift 4
  • Sorry, I was not aware of this. Thanks for the link to the tutorial! Maybe you could edit your question and refer to the link there?
  • Ok thanks! At leats that confirms my gut feelings. So, the reason why the entire share extension dismisses when tapping on "Team" must be some kind of crash, because something else is wrong?
  • Did help! and I found the solution to the rest of the issue :)