Social Framework For Facebook - Placeholder Text in Swift - ios

As stated by facebook, prefill is not allowed anymore with the social framework. But as the statement below;
Your app’s composer can include a call-to-action that disappears when people start to write a post. For example, Facebook's composer uses grey scale text to ask “What's on your mind?” that disappears when people start to write.
Can we put a placeholder text that dissapears when a user starts to write text via the social framework facebook share?
Currently my initial text code which is below is not working.
func facebookShareFunc() {
let shareToFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
shareToFacebook.setInitialText(“Initial text here”)
shareToFacebook.completionHandler = {
(result:SLComposeViewControllerResult) in
let getResult = result as SLComposeViewControllerResult;
switch(getResult.rawValue) {
case SLComposeViewControllerResult.Cancelled.rawValue: print("User cancelled post")
case SLComposeViewControllerResult.Done.rawValue: self.workingFunc()
default: print("Shouldn't happen")
}
}
self.presentViewController(shareToFacebook, animated: true, completion: nil)
}

Related

Firebase Phone Authentication - Long Delay & Multiple OTPs

I'm working on an iOS app project that involves Firebase's phone authentication. I have it working fine on simulator, my iPhone, and my iPad. However, now that I am in the TestFlight stage , my external testers are experiencing long delays in receiving their OTPs as well as receiving duplicates when they reach the ViewController where they enter the OTP code (This is probably due to them hitting the button multiple times).
I also have APNs enabled and working properly.
I don't have much code to share as I followed Firebase's documentation.
What could be some reasons for a long delay in receiving the OTP code from Firebase? I will be including an activity spinner in the project when users tap the sign-in button. However, I also don't want it to be spinning for a minute as users wait for their OTP.
#objc func phoneSignIn() {
guard let phoneNumber = startVerificationView.phoneNumberTextField.text else { return }
let completePhoneNumber = "+1\(phoneNumber)"
Auth.auth().settings?.isAppVerificationDisabledForTesting = isVerificationDisabled
PhoneAuthProvider.provider().verifyPhoneNumber(completePhoneNumber, uiDelegate: nil) { (verificationId, error) in
if error == nil {
guard let verifyId = verificationId else { return }
UserDefaults.standard.set(verifyId, forKey: "verificationId")
let vc = CheckVerificationViewController()
vc.modalPresentationStyle = .fullScreen
vc.completePhoneNumber = completePhoneNumber
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
Also isVerificationDisabled is set to false.

How to know if user shared my app or not?

My app is all about getting points and winning money, and what I need to do is let the user share my app then give him some points.
The problem is that I don't know how to detect if the user truly shared the app or not
I'm using the following code:
func shareTapped(){
let text = "example"
let url = URL(string: "example.com")
let image = UIImage(named: "example_image")
let shareViewController = UIActivityViewController(activityItems: [text, image!, url!] ,applicationActivities: nil)
self.present(shareViewController, animated: true, completion: {() in
print("done")
})
}
The sharing method is working perfectly, but I was wondering if there is any delegate we can call in this situation.
Thanks.
So there is 2 scenarios where user can cancel share.
One is when UIActivityViewController present then there is a cancel button on UIActivityViewController from where user can cancel it and yes you can detect it with method
shareViewController.completionWithItemsHandler = { activity, completed, items, error in
}
In above method completed will be false if user canceled from UIActivityViewController cancel button. and it will return true if user share successfully but here comes second case with it.
So for second case suppose user want to share via watsapp and click on watsapp icon from UIActivityViewController and watsapp user list appear.
But there is a cancel button on that screen from where user can cancel sharing but still you will get completed flag true so there is no way you can detect if user click on cancel button from watsapp user list.

IOS swift how to know when activityViewController has been successfully used

I have a tableView that utilizes the UIActivityViewController so users can share content on other 3rd party networks Facebook, twitter, text message etc. I have a function called IncreaseShareByOne() and it's purpose is to count the number of times that something has been shared . My problem is that right now that function fires of every time the UIActivityViewController is clicked . Is there someway that I can find out if a user really shared something so that I can use that function correctly ? becomes sometimes you open the UIActivityViewController and decide not to share anything so I want to catch and not use that function. I am new to swift and am using version 3 .
func sharedShareAction(controller: UIViewController, sender: UIButton) {
controller.present(activityViewController,animated: true,completion: nil)
IncreaseShareByOne()
}
You can add a completion handler to your UIActivityViewController. In the completion handler, check whether the user submitted using the completed value. You'll probably want to do something like this:
func sharedShareAction(controller: UIViewController, sender: UIButton) {
controller.present(activityViewController,animated: true, completion: nil)
activityViewController.completionWithItemsHandler = { activity, completed, items, error in
if !completed {
// handle task not completed
return
}
IncreaseShareByOne()
}
}
Check the API docs for more info.

Facebook login button does not go to Safari, but goes to app instead, then glitches back

I'm not sure how to replicate the bug consistently yet, but it happens sometimes when I delete the app and reinstall it on a device:
So once in a while when I login with the Facebook button. the Facebook app opens. Usually the way it works is that it is suppose to open the facebook browser on safari.
Anyway it opens the Facebook app, and then goes back to my app without doing anything. And it just keeps doing that over and over every time I press the login button until I delete my app and redownload it. Is anybody else experiencing that? I am using Swift 3.
Here is a gif of the problem:
Gif of Facebook login problem
and here is my code for the Facebook login:
fbLoginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends"], from: self) { (result, error) -> Void in
if (error != nil){
print(error)
let loginManager = FBSDKLoginManager()
loginManager.logOut()
var controller:LoginController
controller = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController
SCLAlertView().showWarning("Login Error #23", subTitle: "Could not log you in, this one is on facebook")
self.present(controller, animated: true, completion: nil)
} else {
print("logging in")
}
}
There are serval behavior options to login with Facebook SDK, you can choose one by setting loginBehaviorproperty of fbLoginManager:
typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior) {
/*!
*/
FBSDKLoginBehaviorNative = 0, /*!
*/
FBSDKLoginBehaviorBrowser, /*!
*/
FBSDKLoginBehaviorSystemAccount, /*!
*/
FBSDKLoginBehaviorWeb,
};
In your case, you can set it to FBSDKLoginBehaviorBrowser, an example could be :
func fbLogin(){
//firstly check whether system fb account available, if so use it
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
fbLoginManger.loginBehavior = FBSDKLoginBehavior.SystemAccount
}
//then check whether fb app available, if so open it
else if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb://")!){
fbLoginManger.loginBehavior = FBSDKLoginBehavior.Native
}
//lastly, present a popup web inside app
else{
fbLoginManger.loginBehavior = FBSDKLoginBehavior.Web
}
fbLoginManger.logInWithReadPermissions(["public_profile"], fromViewController: self) { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
...
}

Social Framework doesn't work properly Swift

I want to have a share button in my app for sharing to Facebook.
I decided to do it with the social framework as i believed it was easier.
I was wrong...
Here is my code:
#IBAction func facebookButton(sender: AnyObject) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
let fbSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
fbSheet.setInitialText("Some text")
fbSheet.addImage(UIImage(named: "loading"))
fbSheet.addURL(NSURL(string: "http://www.something.com"))
presentViewController(fbSheet, animated: true, completion: nil)
} else {
self.showAlert("Facebook", msg: "Please login to your Facebook account in Settings")
}
}
This code is working, but it returns only the url and if I comment it; it returns only the image.
I have changed the order and I put image third but again it returns only the url.
It's like it has priorities and it returns only one of them.
Since last year Facebook doesn't allow to prefill the text if you want to share something. You can set only hashtags as setInitialText. something like this
fbSheet.setInitialText("#\(appname)")
https://developers.facebook.com/docs/apps/review/prefill

Resources