I am adding social media functions on my app and I want to be able to put my own image in the box on the right when the user shares it on their facebook.
I have attached the code I used below. How do I make it so I can add a image so it will be shown when the user posts it on their facebook?
Thanks in advance
#IBAction func facebook(_ sender: Any)
{
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook)
{
let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
vc?.setInitialText("How many of these expressions can you relate to? http://www.example.com")
vc?.add(URL(string: "https://www.facebook.com"))
present(vc!, animated: true, completion: nil)
}
else
{
print("error")
}
}
Related
I would like to redirect the user to an app that could be selected in UIActivityViewController.
For example, the "Message" app is often shown in UIActivityViewController. How could I,in advance, directly redirect the user to this app without showing the UIActivityViewController?
I would be glad to know if someone can help me out.
If you need to open the Messages App, it's simple.
#IBAction func openMessagesApp(sender: UIButton){
// Swift 3
UIApplication.sharedApplication().openURL(NSURL(string: "sms:")!)
// Swift 4
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
}
Try this one!
#IBAction func openMessagesApp(sender: UIButton){
let sms = "sms:\(number)&body=\(message or link)"
let url = URL(string:sms)!
let shared = UIApplication.shared
if(shared.canOpenURL(url)){
shared.openURL(url)
} else{
print("unable to send message")
}
}
Hi I am writing the following code to refer a friend through SMS.
When I click on cell, the sms app opens with text but when again I tried for second time, it shows white color screen.
Here is my code
var controller1 = MFMessageComposeViewController()
extension ReferaFriendController:UICollectionViewDelegate,UICollectionViewDataSource,MFMessageComposeViewControllerDelegate
{
if indexPath.item == 0
{
if MFMessageComposeViewController.canSendText() {
let urlToShare = self.referalmodeldata[0].referralCodeOnly
controller1.body = "Hey I just gave an Awesome Assessment on App you can also try it. I scored , Try to beat my score \(String(describing: urlToShare))"
controller1.messageComposeDelegate = self
self.present(controller1, animated: true, completion: nil)
}
}
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
self.dismiss(animated: true, completion: nil)
}
}
As far as I can see, there's no need to keep a reference to the MFMessageComposeViewController. Just move it to be created at the point you need it, inside your if closure:
if MFMessageComposeViewController.canSendText() {
let controller = MFMessageComposeViewController()
// ...
}
I have followed the Places API tutorial on Google's website, and I have double checked that the Places API for iOS is enabled and that my API key is in my AppDelegate. I have definitely implemented GMSPlacePickerViewControllerDelegate in my class. The Places Picker will open, I can view places, and I can tap on them, and I can search. I cannot get out of this screen, I cannot cancel, I cannot actually select anything or return a location. This is the same on a physical device and on the simulator. Why doesn't it work, and how can I make it work?
#IBAction func selectLocationPressed(_ sender: Any) {
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
present(placePicker, animated: true, completion: nil)
}
// To receive the results from the place picker 'self' will need to conform to
// GMSPlacePickerViewControllerDelegate and implement this code.
func placePicker(_ viewController: GMSPlacePickerViewController,
didPick place: GMSPlace) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("Place name \(place.name)")
print("Place address \(place.formattedAddress)")
print("Place attributions \(place.attributions)")
}
func placePickerDidCancel(_ viewController:
GMSPlacePickerViewController) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("No place selected")
}
Implement GMSPlacePickerViewControllerDelegate protocol in your class and set placePicker.delegate = self
I've been playing around for couple days with IOS and Google Maps Api and two days ago the API was upgraded to the version 2.3 which deprecate the use of GMSPlacePicker.
Deprecation notice: GMSPlacePicker
Notice: The implementation of the place picker has changed. As of version 2.3 of the Google Places API for iOS, the GMSPlacePicker class is deprecated, replaced by GMSPlacePickerViewController. Use of the GMSPlacePicker class will only be supported until May 1, 2018. We recommend that you update your code to use GMSPlacePickerViewController when possible.
In my code I switched to GMSPlacePickerViewController however I still get an error on the logs saying :
Places API warning: A delegate has not been set on an instance of GMSPlacePickerViewController before use. Note that this may result in undefined behavior such as being unable to dismiss screens, not being notified of selections, and being unable to correctly manage object lifecycle.
Even though my class is extending the delegate
class ReportController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,GMSPlacePickerViewControllerDelegate{
// code goes here
}
Any idea how to solve this ?
I had also the same problem I resolved this by using this code.
Here is the code .
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
Hope this will also resolve your problem
GoogleMap version 2.3
The document also make me feel confuse in version 2.3
The picture below is a picture that I crop from the google document.
This link is a document from google map SDK for this Solution
you just write the code according to document and add a one line of code below the code was accentuated by the red pen.
The code that I wrote accordingly from document below here
// The code snippet below shows how to create and display a GMSPlacePickerViewController.
#IBAction func pickPlace(_ sender: UIButton) {
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
}
// To receive the results from the place picker 'self' will need to conform to
// GMSPlacePickerViewControllerDelegate and implement this code.
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("Place name \(place.name)")
print("Place address \(String(describing: place.formattedAddress))")
print("Place attributions \(String(describing: place.attributions))")
}
func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("No place selected")
}
I am using Swift and the OAuthSwift pod to handle OAuth using an in app SFSafariViewController. Here's what it looks like for sign in:
The thing is, when I try to log out with this code:
#IBAction func signOutButtonPressed(_ sender: AnyObject) {
let svc = SFSafariViewController(url: URL(string: "https://squareup.com/logout")!)
self.present(svc, animated: true, completion: {
print("signed outttt")
appStore.dispatch(AppAction(type: .MerchantLogout()))
})
}
It opens the browser again and shows that page. The user is successfully logged out (the cookies are reset, etc) but I would like the browser to just close instead of showing the sign in form again. Signing in through that form does not call my OAuth callback. Instead it just signs them in and sends them to the square dashboard.
What's the proper way of signing out the user using an in app SFSafariViewController + OAuth?
Eventually I just ended up doing this:
#IBAction func signOutButtonPressed(_ sender: AnyObject) {
let svc = SFSafariViewController(url: URL(string: "https://squareup.com/logout")!)
self.present(svc, animated: true, completion: {
appStore.dispatch(AppAction(type: .MerchantLogout()))
self.dismiss(animated: false, completion: nil)
})
}