Use of unresolved identifier: PFTwitterUtils swift - ios

Currently I'm trying to implement a twitter user login for my app in Xcode 7 beta with parse. I followed the docs at parse.com for twitter. After implementing, I am still running to use of unresolved identifier for
PFTwitterUtils.initializeWithConsumerKey("somekey", consumerSecret:"somekey")
and
#IBAction func twitterButtonTapped(sender: AnyObject) {
PFTwitterUtils.logInWithBlock {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
// process user object
self.processTwitterUser()
} else {
// process user object
self.processTwitterUser()
}
} else {
print("Uh oh. The user cancelled the Twitter login.")
}
}
}
and
func processTwitterUser()
{
// Show activity indicator
let spiningActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
spiningActivity.labelText = "Loading"
spiningActivity.detailsLabelText = "Please wait"
let pfTwitter = PFTwitterUtils.twitter()
let twitterUsername = pfTwitter?.screenName
var userDetailsUrl:String = "https://api.twitter.com/1.1/users/show.json?screen_name="
userDetailsUrl = userDetailsUrl + twitterUsername!
let myUrl = NSURL(string: userDetailsUrl);
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "GET";
pfTwitter!.signRequest(request);
any common pitfalls I might have fell into?
Note: I added the correct frameworks (accounts etc.)

Here is a solution that worked for me.
I added the "ParseTwitterUtils.framework"
In my Bridging header I added "#import ParseTwitterUtils/ParseTwitterUtils.h "
In my AppDelegate.Swift I added "import ParseTwitterUtils"
I filled the consumerKey and secretKey (You'll find them on your Twitter dev account)
And now it's working
Hope it helped

Related

Show AdMob gdpr consent form in Xcode

I have developed my game in Godot game engine and I'm now trying to implement googles gdpr consent form into my Xcode project.
I am using Xcode 11.5
The code below is my current code which does not result in the consent form popping up.
It might be something with the class I made but I'm not sure how that works.
import UIKit
import PersonalizedAdConsent
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PACConsentInformation.sharedInstance.requestConsentInfoUpdate(
forPublisherIdentifiers: ["I have the id just not posted here"])
{(_ error: Error?) -> Void in
if let error = error {
// Consent info update failed.
} else {
// Consent info update succeeded. The shared PACConsentInformation
// instance has been updated.
}
}
guard let privacyUrl = URL(string: "My_privacy_policy(not_actual)"),
let form = PACConsentForm(applicationPrivacyPolicyURL: privacyUrl) else {
print("incorrect privacy URL.")
return
}
form.shouldOfferPersonalizedAds = true
form.shouldOfferNonPersonalizedAds = true
form.shouldOfferAdFree = false
form.load {(_ error: Error?) -> Void in
print("Load complete.")
if let error = error {
// Handle error.
print("Error loading form: \(error.localizedDescription)")
} else {
// Load successful.
}
}
//Finally present the consent form
form.present(from: self) { (error, userPrefersAdFree) in
if let error = error {
// Handle error.
} else if userPrefersAdFree {
// User prefers to use a paid version of the app.
} else {
// Check the user's consent choice.
let status =
PACConsentInformation.sharedInstance.consentStatus
}
}
}
}
Any help is appreciated :)

Admob IOS swift GDPR consent

I'm new to swift and iOS programming. I want to add Admob consent/GDPR option to my app,
So I've setup an ad box and can display a test add, but need to add consent option next.
I've read
https://developers.google.com/admob/ios/eu-consent
but it's not clear to me, can anyone show me an example of code to do this step by step, or point me to GitHub source where it has been done.
Thanks
Can you please show an example of what you have tried that isn't working for you?
As I am unable to see your code example to see what you're doing or not doing, I'll give an example based on the docs.
import PersonalizedAdConsent
...
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PACConsentInformation.sharedInstance.
requestConsentInfoUpdate(
forPublisherIdentifiers: ["pub-0123456789012345"])
{(_ error: Error?) -> Void in
if let error = error {
// Consent info update failed.
} else {
// Consent info update succeeded. The shared PACConsentInformation
// instance has been updated.
}
}
guard let privacyUrl = URL(string: "https://www.your.com/privacyurl"),
let form = PACConsentForm(applicationPrivacyPolicyURL: privacyUrl) else {
print("incorrect privacy URL.")
return
}
form.shouldOfferPersonalizedAds = true
form.shouldOfferNonPersonalizedAds = true
form.shouldOfferAdFree = true
form.load {(_ error: Error?) -> Void in
print("Load complete.")
if let error = error {
// Handle error.
print("Error loading form: \(error.localizedDescription)")
} else {
// Load successful.
}
}
//Finally present the consent form
form.present(from: self) { (error, userPrefersAdFree) in
if let error = error {
// Handle error.
} else if userPrefersAdFree {
// User prefers to use a paid version of the app.
} else {
// Check the user's consent choice.
let status =
PACConsentInformation.sharedInstance.consentStatus
}
}
}

Firebase Passwordless Email Authentication doesn't open app on iOS

I'm trying and failing badly to implement the cool Firebase email link login feature. I successfully setup sending an email link. However, I can't get the email link to open up the app. It just opens up the preview page like it can't open the app.
I've tested the dynamic link I setup and I can get it to open up the app in a device. I just can't get the email link to do the same.
Code in my app:
func sendFirebaseEmailLink() {
let actionCodeSettings = ActionCodeSettings.init()
// userEmail comes from a textField
let email = userEmail
actionCodeSettings.url = URL.init(string: String(format: "https://<myappname>.firebaseapp.com/?email=%#", email))
// The sign-in operation has to always be completed in the app.
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
Auth.auth().sendSignInLink(toEmail: email,
actionCodeSettings: actionCodeSettings) { error in
if let error = error {
print(error.localizedDescription)
return
}
else {
UserDefaults.standard.set(email, forKey: "Email")
print("email sent to user")
}
}
}
When I say I've successfully gotten my dynamic link to open the app what I mean is when I follow the link I created (mylinkname.page.link/emaillogin) on a device that has the app installed, it opens the app. Because of that and [this helpful Firebase video][1] on setting up a dynamic link it seems like I've got those details correct and the issue is with the code, but I'm new to this so I'm not sure.
I've spend few days going around in circles to figure this out, and trying to parse the dense Firebase documentation, so any ideas are greatly appreciated.
I finally figured it out. The code was fine. It was an issue related to the dynamic link. I had a couple links setup in Firebase because I had to create a new Bundle ID at one point. When I deleted out the old one in Firebase the email link started working.
It shows up in my app association site like this, and oddly still does even though I deleted out the old link, but at least it works now!
{"applinks":{"apps":[],"details":[{"appID":"TEAMID.com.OLDBUNDLEIDENTIFIER.APPNAME","paths":["NOT //*","/*"]},{"appID":"TEAMID.com.NEWBUNDLEIDENTIFIER.APPNAME","paths":["NOT //","/"]}]}}
UPDATE: My full code to implement passwordless email login is below. It was painful for me to piece together using the documentation so hopefully this saves you the trouble.
Key steps assuming you understand the basics of Firebase Setup.
1) Setup a Dynamic Link Using the Firebase Video tutorial.
2) Code in View Controller:
var userEmail: String?
var link: String?
func sendFirebaseEmailLink() {
let actionCodeSettings = ActionCodeSettings.init()
let email = userEmail
actionCodeSettings.url = URL.init(string: String(format: "https://<myappname>.page.link/emaillogin/?email=%#", email!))
// The sign-in operation has to always be completed in the app.
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
Auth.auth().sendSignInLink(toEmail: email!,
actionCodeSettings: actionCodeSettings) { error in
if let error = error {
print(error.localizedDescription)
return
}
else {
UserDefaults.standard.set(email, forKey: "Email")
print("email sent to user")
}
// TODO: Notify user to check email and click the link.
}
}
// Sign in user after they clicked email link called from AppDelegate
#objc func signInUserAfterEmailLinkClick() {
// Get link url string from the dynamic link captured in AppDelegate.
if let link = UserDefaults.standard.value(forKey: "Link") as? String {
self.link = link
}
// Sign user in with the link and email.
Auth.auth().signIn(withEmail: userEmail!, link: link!) { (result, error) in
if error == nil && result != nil {
if (Auth.auth().currentUser?.isEmailVerified)! {
print("User verified with passwordless email")
// TODO: Do something after user verified like present a new View Controller
}
else {
print("User NOT verified by passwordless email")
}
}
else {
print("Error with passwordless email verfification: \(error?.localizedDescription ?? "Strangely, no error avaialble.")")
}
}
}
3) Code in AppDelegate
// For Passwordless Email Login to Handle Dynamic Link after User Clicks Email Link
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
print("Incoming URL is \(incomingURL)")
// Parse incoming
let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
guard error == nil else {
print("Found an error: \(error!.localizedDescription)")
return
}
if let dynamicLink = dynamicLink {
self.handleIncomingDynamicLink(dynamicLink)
}
}
if linkHandled {
return true
}
else {
// Maybe do other things with dynamic links in future?
return false
}
}
return false
}
// Handles the link and saves it to userDefaults to assist with login.
func handleIncomingDynamicLink(_ dynamicLink: DynamicLink) {
guard let url = dynamicLink.url else {
print("My dynamic link object has no url")
return
}
print("Incoming link parameter is \(url.absoluteString)")
let link = url.absoluteString
if Auth.auth().isSignIn(withEmailLink: link) {
// Save link to userDefaults to help finalize login.
UserDefaults.standard.set(link, forKey: "Link")
// Send notification to ViewController to push the First Time Login VC
NotificationCenter.default.post(
name: Notification.Name("SuccessfulPasswordlessEmailNotification"), object: nil, userInfo: nil)
}
}
For anyone using SwiftUI with AppDelegate and SceneDelegate files instead of UIKit, here's what I've done:
Create a function to send a link to the user's email
func sendSignLink(email: String) async throws {
do {
let actionCodeSettings = ActionCodeSettings()
actionCodeSettings.url = URL(string: "*enter your Firebase Dynamic link here*")
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
try await Auth.auth().sendSignInLink(toEmail: email, actionCodeSettings: actionCodeSettings)
UserDefaults.standard.set(email, forKey: "email")
}
catch {
throw error
}
}
In the SceneDelegate file, import FirebaseDynamicLinks and add the below code
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let incomingURL = userActivity.webpageURL {
print("\n \nIncoming URL is \(incomingURL)")
_ = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
guard error == nil else {
print("\n \nError with handling incoming URL: \(error!.localizedDescription)")
return
}
if let dynamicLink = dynamicLink {
guard let url = dynamicLink.url else {
print("\n \nDynamic link object has no url")
return
}
print("\n \nIncoming link parameter is \(url.absoluteString)")
let link = url.absoluteString
if Auth.auth().isSignIn(withEmailLink: link) {
// Send notification to trigger the rest of the sign in sequence
NotificationCenter.default.post(name: Notification.Name("Success"), object: nil, userInfo: ["link": link])
} else {
// Send error notification
NotificationCenter.default.post(name: Notification.Name("Error"), object: nil, userInfo: nil)
}
}
}
}
}
Create a function to handle the sign in after the user has clicked on the link in their email
func signInWithEmail(link: String) async throws {
do {
let email = UserDefaults.standard.value(forKey: "email")
try await Auth.auth().signIn(withEmail: email, link: link)
}
catch {
throw error
}
}
In a relevant view, handle the notifications which get posted
struct MyView: View {
var body: some View {
VStack {
Text("View")
}
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("Success"))) { notificationInfo in
if let userInfo = notificationInfo.userInfo {
if let link = userInfo["link"] as? String {
Task.init {
do {
try await signInWithEmail(link: link)
} catch {
print(error)
}
}
}
}
}
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("Error"))) { _ in
//do something with error
}
}
}

Facebook Pages, ask which page user choose, and take id, name, and ratings IOS SWIFT 3-4

First sorry for my English, I'm a French developer.
for 1 week, I read and reread the Facebook documentation but it does not work.
This is my problem:
On Xcode, I can create the connection with Facebook, the user can connect with his account and I managed to recover his image and surname / first name.
On another page, I ask for access token for [manage_pages], the application asks permission but when the user has several pages they do not propose to manage one, Authorization I can not retrieve the ID or name of the Facebook page. I leave you the code on the Options page which allows you to request authorization to connect your Facebook page after the user presses a button.
I tried with access graph: / me / accounts ... etc without success. It's really because I really have no idea that I'm coming to you. Thank you in advance for your answers !
#IBAction func connect_Pages(_ sender: Any) {
loginButtonClicked()
}
func loginButtonClicked() {
let login:FBSDKLoginManager = FBSDKLoginManager.init()
login.logIn(withPublishPermissions: ["manage_pages"], from: self) { (resultPAge, error) in
if((error) != nil) {
print("error")
}
else if (resultPAge?.isCancelled)! {
print("cancel")
}
else {
if (resultPAge?.grantedPermissions.contains("manage_pages"))! {
if resultPAge?.token == nil {
print("error")
}
else {
let graphRequest = FBSDKGraphRequest(graphPath: "/me/accounts", parameters: ["fields" : "access_token, name, id"])
let connection = FBSDKGraphRequestConnection()
print("connect")
connection.add(graphRequest, completionHandler: { (connection, result, error) -> Void in
if let dataRecup = result as? [String:AnyObject] {
if let idPage = dataRecup["data"] as? [String:AnyObject] {
if let nomPage = idPage["name"] as? String {
print("Resultat : \(nomPage)")
}
}
}
})
}
}
}
}
}
EDIT :
I just removed the first / for the graphpath, but a new problem appeared, I retrieve the information from the page (accessToken, id and name) but there are no quotation marks! The application can not recover it to separate in JSON.

How to open Facebook Messenger and direct to someone?

I have FBSDK already and can use FBSDKShareKit send something on Messenger.
I want just open a chat with someone in Facebook Messenger. like this:
Click a button in my app(sample: Facebook app):
http://i.imgur.com/j60P3Ng.png
Go to Facebook Messenger and open a chat with this person:
http://i.imgur.com/yU0EXKF.png
How Can I do it?
Swift 4
UI
In my app I show a user's Facebook ID as a button:
Code
#IBAction func messengerButton(_ sender: UIButton) {
if let id = sender.titleLabel?.text {
if let url = URL(string: "fb-messenger://user-thread/\(id)") {
// Attempt to open in Messenger App first
UIApplication.shared.open(url, options: [:], completionHandler: {
(success) in
if success == false {
// Messenger is not installed. Open in browser instead.
let url = URL(string: "https://m.me/\(id)")
if UIApplication.shared.canOpenURL(url!) {
UIApplication.shared.open(url!)
}
}
})
}
}
}
User's Facebook ID
The user can get another person's Facebook ID from looking them up on Facebook and then observing the URL:
I found a solution with URL Scheme:
let userID = 4
let urlStr = String(format: "fb-messenger://user-thread/%d", userID)
let theUrl = NSURL(string: urlStr)
[UIApplication.sharedApplication() .openURL(theUrl!)]
This code will open Message application and talk to Mark.
in swift 5.1, use
guard let messenger = URL(string: "fb-messenger://user-thread/your_id") else { return }
UIApplication.shared.open(messenger)

Resources