I'm experimenting adding a Facebook like button to my app using swift. This is my code and also the steps I exactly took until now. I am wondering if I am missing doing any steps or if there is something wrong with the code?
1- Created a new Xcode project using Swift
2-added the following code to viewDiDLoad
3-imported "import Parse" and "import Social" as seen below
4-Created a bridging header file and imported FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h into it.
5-Added FBSDKCoreKit and FBSDKShareKit to my frameworks
And then I'm getting an "expected declaration" error on this line:
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
Here is the full code:
import UIKit
import Parse
import Social
class NewsPageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeButton.frame = CGRectMake(16,20, 290, 40)
self.view.addSubview(likeButton)
}
}
The issue was I wanted to push a button and then have the like button show up. So I added an IBAction and it's working like gold! next for me is to figure a way to change the button image :)
here is the working code by the way:
import UIKit
import Parse
import Social
class NewsPageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func likeOnFacebook(sender: AnyObject) {
var likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeButton.frame = CGRectMake(16,20, 290, 40)
self.view.addSubview(likeButton)
}
}
Related
I'm sorry if the title is confusing, i'm kind of new to the whole thingy.
I'm trying to integrate PassBase ID verification to my app, which is built using SwiftUI, their documentation offers instructions using Swift and view Controllers.
My question is, is there a way to insert the Swift code part into my SwiftUI view?
The code example from their Documentation:
import Passbase
import UIKit
class ViewController: UIViewController, PassbaseDelegate {
override func viewDidLoad() {
super.viewDidLoad()
PassbaseSDK.delegate = self
// Optional - You can prefill the email to skip that step.
Passbase.prefillUserEmail = "testuser#yourproject.com"
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
func onFinish(identityAccessKey: String) {
print("onFinish with identityAccessKey \(identityAccessKey)")
}
func onSubmitted(identityAccessKey: String) {
print("onSubmitted with identityAccessKey \(identityAccessKey)")
}
func onError(errorCode: String) {
print("onError with code \(errorCode)")
}
func onStart() {
print("onStart")
}
}
As i understand this part of code should create a button in a VC.
My goal is to add this button with functionality to my SwiftUI view.
Full Documentation: https://docs.passbase.com/ios#general
Thank you all in advance for the help!
The basic strategy is to use a View that represents the content you want to bring in from a UIViewController. Your View is going to conform to UIViewCotrollerRepresentable and use the functions of that protocol to create and manage the UIKit content.
The UIViewControllerRepresentable documentation is here
And, as was commented on your original post by vadian, there is A tutorial with sample code
With the sample code above, I would rename "ViewController" to be something like PassBaseViewController or PBViewController, then you would create a View that derives from UIViewControllerRepresentable
You end up with a file called PBViewController.swift that has your code from above:
import Passbase
import UIKit
class PBViewController: UIViewController, PassbaseDelegate {
override func viewDidLoad() {
super.viewDidLoad()
PassbaseSDK.delegate = self
// Optional - You can prefill the email to skip that step.
Passbase.prefillUserEmail = "testuser#yourproject.com"
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
... and the rest of the code from your question here ...
Then (probably in another file, but not necessarily) you could create the SwiftUIView that uses that view controller:
struct PassBaseView : UIViewControllerRepresentable {
typealias UIViewControllerType = PBViewController
func makeUIViewController(context: Context) -> PBViewController {
return PBViewController()
}
func updateUIViewController(_ uiViewController: PBViewController, context: Context) {
/* code here to make changes to the view controller if necessary when this view is updated*/
}
}
I am using left side menu from this pod. here I have given storyboard side menu button to UISideMenuNavigationController Present Modually Segue and side menu is working fine and here I want to use its delegate methods delegate methods
but here i am getting below error why??
I have import it in swift file and just clean the build, restart the mac still same error why?? any idea please help me.
I have written below code:
import UIKit
import SwiftKeychainWrapper
import SideMenu
class ProfileViewController: UIViewController, UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func sideMenubtn(_ sender: Any) {
view?.backgroundColor = UIColor(white: 1, alpha: 0.9)
}
}
extension ProfileViewController : SideMenuNavigationControllerDelegate {
func sideMenuWillDisappear(menu: SideMenuNavigationController, animated: Bool) {
view?.backgroundColor = UIColor.white
}
}
I got this error:
Use of undeclared type SideMenuNavigationControllerDelegate
Use of undeclared type SideMenuNavigationController
This is small demo project you can find pod installing and error here github demo project
please help me.
As I can see in your Podfile.lock you are using SideMenu 5.0.3. This is not the latest version of this library. Please use SideMenu 6.4.7. Replace pod 'SideMenu' with pod 'SideMenu', '6.4.7' in your Podfile and run pod update. With SideMenu 6.4.7 your demo project builds without any errors.
The problem is: I have an implementation of the textToSpeech on swift and weirdly it doesn't work on my iPhone, but when I use the simulator it does!
Here's a simple code:
import UIKit
import AVFoundation
class ViewController: UIViewController, AVSpeechSynthesizerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func buttonPushed(sender: UIButton) {
let utterance = AVSpeechUtterance(string:"This is a test")
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
let voice = AVSpeechSynthesizer()
voice.delegate = self
voice.speak(utterance)
}
}
It used to work before I update my xcode to version 9.2, so I don't know what to do. Spent the whole day on this and nothing!
Weirdly, have another view controller which I use for recording voice and pass it to text (speechToText) and when I try this, then the textToSpeech start working on my iPhone, that's the only way it works. I don't know why as my textToSpeech and speechToText are in different view controllers and they are not related.
Any help would be very much appreciated!
Hi I am trying to make a FB Like button in my app. I have seen a lot of posts and they are old and not clear for me.
Here is what I did:
import FBSDKCoreKit
import FBSDKShareKit
class MyClass{
#IBOutlet weak var fbLikeButton: FBSDKLikeButton!
override func viewDidLoad() {
super.viewDidLoad()
self.fbLikeButton.objectID = "MyPage"
}
}
In the story board I Chose FBSDKLikeButton as class for the button in the Identity inspector.
Now:
1. This dosent work.
2. I want to do the FBSDKLikeControlStyle.BoxCount if possible.
I tried to do like this without FBSDKLikeButton as class for the button in the Identity inspector :
import FBSDKCoreKit
import FBSDKShareKit
class MyClass{
#IBOutlet weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let likeControl:FBSDKLikeControl = FBSDKLikeControl()
likeControl.objectID = "MyPage"
likeControl.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeControl.frame = CGRectMake(15, 15, 200, 40)
likeControl.likeControlHorizontalAlignment = .Left
self.contentView.addSubview(likeControl)
}
}
It appeared but it didnt affect number of likes.
Any clear direct solution?! All the posts are old. I hope this will be a new clear one.
Thx
I'm trying to add an objective-C/CocoaPods code (GBFlatButton) to an existing swift code. I read all about I found regarding Header settings and I did this, let me know if is well performed.
Header Bridging configuration
Also the Header file has the right import files added to it.
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <UIKit/UIKit.h>
#import <GBFlatButton/GBFlatButton.h>
#import <GBFlatButton/UIColor+GBFlatButton.h>
On the other hand the CocoaPods project doesn't give me an error when I compile the code. The error occurs when I use the button, maybe is the way I'm trying to use this objective-c code:
let MyButton: GBFlatButton! = GBFlatButton(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 40.0))
Also I tried to use it like this: #IBOutlet var FButton: GBFlatButton!
This is the final error I have:
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:19:
Use of undeclared type 'GBFlatButton'
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:9:
Could not infer type for 'MyButton'
Any clue will help :)
Thanks!!, if you need more info don't hesitate to ask me.
you forgot to add the bridging header in the Build settings of the app
In ViewController:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button: GBFlatButton! = GBFlatButton(frame: CGRectMake(0, 0, 200, 50))
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
just do this and then it will work