I'm developing an iOS app with swift and I need to share a message with the telegram app when a button is pressed. I want the user to choose which contact he/she wants to share the message with.
I've tried the "tg://msg?text=" schema but it only opens telegram not the sharing page to choose a contact.
Does anyone know a way for doing this?
Thank you in advance for your help !
Answer:
As #Cesare pointed out the tg://msg?text=test URL had been disabled by telegram so we need a specific phone number to share the message with.
Telegram disabled the tg://msg?text=test URI. You can only send direct messages to pre-chosen users or contacts.
So you may want to present a standard contact list and then send a message to that phone number (assuming they have Telegram).
For sure if you use a UIActivityController that should work.
#objc func didSelectShareRow() {
let text = "Hello"
let textShare = [text]
let activityViewController = UIActivityViewController(activityItems: textShare , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
}
Another solution would be to use something like my LNExtensionExecutor, which allows you to bypass the UIActivityViewController and execute the standard Telegram (or any other) share extension, providing text and/or images as input items.
Related
Im using TwiterKit 3.0 framwork. And im using Deeplink to share a tweet for my application. But the problem is its presenting a new viewController and shows the twitter dialogue box. But my requirement is need to share like in Photos app sharing screen.
if let deepLinkurl = branchObject.getShortUrl(with: shareLinkProperties) {
let composer = TWTRComposer()
composer.setURL(URL(string: deepLinkURL))
composer.show(from: self) { result in
if (result == TWTRComposerResult.cancelled) {
print("Tweet composition cancelled")
}
}
If i run above code I get like this
But I need something like this.
You can use Branch's showShareSheet() method for sharing Branch links to other apps.
Here is how the link is shared when using the shareSheet and selecting Twitter from the list of the Apps.
You can check out the documentation here
I'm currently using Fastlane Snapshot to automate taking screenshots for my application. It's all based on UI Tests.
I'm trying to add this same functionality to an iMessage App/Extension.
So currently I have a test that goes through taps buttons, fills in text fields, takes the screenshots, etc.
After all that is done I'd like it to close the application (click the home button), open iMessage, interact with my iMessage application and take some screenshots there as well.
Is this possible? If so how can I achieve this? Automating screenshots for this one application has been amazing and I'd love to be able to do that for the iMessage App as well.
There is no UI Tests for iMessage app extension in Xcode currently. But you can perform it by launching Messages by yourself and find elements in the Messages app. At first, you'll have to launch the Message app and open a conversation :
let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS")
messageApp.terminate()
messageApp.activate()
messageApp.cells.firstMatch.tap()
Then, you can access your iMessage app by doing so :
// Replace appIndex by the position of your app in the iMessage bottom bar
let appIndex = 2
messageApp.collectionViews.descendants(matching: .cell).element(boundBy: appIndex).tap()
When your iMessage app is opened in the expanded mode, you can access the close button :
let closeButton = messageApp.buttons.element(boundBy: 1)
If you want to test your iMessage app when the user send a message and then open it, you can do it this way :
// Send your message after it is inserted in the Messages app text field
let sendButton = messageApp.buttons["sendButton"]
waitForElementToExists(sendButton)
sendButton.tap()
// Tap on the iMessage first bubble
let firstBubble = messageApp.collectionViews["TranscriptCollectionView"].cells.element(boundBy: 2)
waitForElementToExists(firstBubble)
firstBubble.tap()
private func waitForElementToExists(_ element: XCUIElement) {
let exists = NSPredicate(format: "exists == 1")
expectation(for: exists, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: 5, handler: nil)
}
With Xcode 9 you can easily switch to the other applications like Messages. The following code switches to Messages, interacts with elements within the app and then switches back to your own app.
let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS")
messageApp.terminate()
messageApp.activate()
messageApp.cells.staticTexts["Kate Bell"].tap()
XCUIApplication().activate()
I am trying to share something via the branch.io share sheet:
let shareText = "Some Share Text"
let linkProperties = BranchLinkProperties()
linkProperties.feature = "Some"
linkProperties.addControlParam("$desktop_url", withValue: desktopURLString)
linkProperties.addControlParam("$android_url", withValue: androidURLString)
let object = BranchUniversalObject(canonicalIdentifier: "some.cannonical.identifier")
object.title = "Some Title"
object.imageUrl = someImageURL
object.contentDescription = "Some Content Description"
object.addMetadataKey("some_id", value: identifier)
object.showShareSheet(with: linkProperties,
andShareText: shareText,
from: self,
completion: completion)
All works great, except that the Facebook Messenger app does not show as option in the share sheet. Neither in the suggested options nor under 'More'. What is needed to achieve that?
I found the following question / answer for the default UIActivityViewController. How does that work with branch.io though? Facebook Messenger not showing up with UIActivityViewController
When you share via a share sheet on iOS - whether you use the Branch share sheet or UIActivityViewController - the choice of sharing options is not yours to define, it is defined by the user.
The interface for setting which apps will appear on the list can be accessed by opening a Share Sheet and then scrolling through the list of presented apps until you see the "..." (More) option. Tap on this button and you will be presented with the list of apps that can be shared to on the phone:
Each app will have a slider - if the slider is enabled for a particular app, that app will appear in the list.
Enabling Facebook Messenger for sharing on a user's phone is not something you can do from within your app as a developer.
You mention that the Messenger app is not even available when you tap the More button. This strikes me as odd; every device I check does have Facebook Messenger as an option if it is installed. Perhaps try removing and reinstalling Facebook Messenger.
I dived into the issue once more and I finally found the trouble maker. If I set feature of the branch link properties to a string value containing a space, Messenger disappears in the share sheet. The example:
let properties = BranchLinkProperties()
properties.feature = "Share News" //does not work, messenger does not appear in the share sheet
//properties.feature = "Share_News" //works, messenger appears in share sheet
object.showShareSheet(with: properties, andShareText: "Some Share Text", from: viewController, anchor: UIBarButtonItem()) { (activityType, completed) in
if (completed) {
print(String(format: "Branch TestBed: Completed sharing to %#", activityType!))
} else {
print("Branch TestBed: Link Sharing Cancelled\n")
}
}
feature is used as a parameter in the URL in Branch which is then given to the sharing extension. While this, I think, is an encoding issue in Branch, it seems that the Messenger sharing extension is not handling the URL in the same way as other apps. The 'broken url' does work with other sharing extensions. Hope this helps someone else! I will change the name of my feature to something without space for now.
I have this simple piece of code to display a sharing dialog for a number of social avenues:
let text = String(format:NSLocalizedString("I %# with the Dhammapada verse \"%#\"", comment:"$ to be composed with $$"), part, verse)
let url = URL(string:"http://www.ipuja.net")
let image = buddhanetImage.image ?? UIImage(named:"Icon-72")
let shareController=UIActivityViewController(activityItems:[text, url!, image!], applicationActivities:nil)
shareController.excludedActivityTypes = [UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList,UIActivityTypePostToVimeo];
if (UI_USER_INTERFACE_IDIOM() == .pad){
shareController.popoverPresentationController?.sourceView = self.buddhanetImage;
}
self.present(shareController, animated:true, completion:nil)
Yet the tool woks fine for Google and Twitter, but when I try to share the contents on Facebook, just the url is shown without either text of image.
I checked that doing the thing on Photos and other other third party apps allows to display the full content even for Facebook, so what is missing in my code for that to work?
The URL will override the text and image when sharing to Facebook from a third-party application. Remove the URL and the image and text will appear. Also, if you have multiple hashtags in your text, only the first hashtag will be applied.
Prior to iOS 9, prefilling the Facebook share dialog with text, image, and URL was possible. Once iOS 9 was released, prefilling any fields when sharing to Facebook was not possible at all. Sometime around iOS 9.3 they reenabled prefilling fields, but prefilling all the fields is not possible.
My app suggests user to share some results(reached inside the App) which collected to one UIImage (so this is not the image with known URL)
I want sharer also to share the link to some page(lets say "stackoverflow.com")
The problem is that if i add a link to controller, sharing controller does not show UIImage(showing page logo or a snippet), otherwise correctly shows UIImage without link.
I use SLComposeViewController, but this is not obligatory.
Due to this issue I can't use FBSDKShareButton (if it's needed). FBSDKSharingDialog does not accept UIImages
code:
//image : UIImage
let fbShareController: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
fbShareController.addImage(image)
fbShareController.addURL(NSURL(string: "www.stackoverflow.com"))
self.presentViewController(fbShareController, animated: true, completion: nil)
Is this new Facebook policy, or my issue?
Thank you for any help.
What you ask is not possible with SLComposeViewController.
The reason is when you add an image it is attached to the post as image. When you add an URL though, SLComposeViewController's private implementation ( or Facebook's backend services ..hard to say which one) takes over and it parses the URL and provides an appropriate image (if one is available as a result of parsing the URL contents) to complement the link.
The post then becomes a post with URL which doesn't show locally attached images.