I am using FacebookSDK to share content on my app! I encountered some problems though when the user is logged in on their iPhone's Facebook account on settings. Doing so seems to override FacebookSDK's sharing functionality, which is not what I wanted to happen.
In both cases, I am using the following lines to share content on Facebook:
let content:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com")
content.contentTitle = "Link Title"
content.contentDescription = "Link Description"
content.imageURL = NSURL(string: "Image Link")
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
Case A: Logged in on Facebook on iPhone Settings (What I don't want)
iPhone logged in shared post
Case B: Logged out of Facebook on iPhone Settings (What I want)
Facebook SDK Sharing
Would also just like to point out that the popup behaviour is also different for Case A and B. Case A's opens facebook sharing via a popup that mimics that of SLComposeViewController, while Case B opens facebook sharing on a browser.
I wanted Case B to happen for reasons that it shows the share via "APP" and not via "iOS" and that it is able to properly share the image. Is there any way to make Case B: happen even if the user is logged on the iPhone settings? Or better yet still proceed with Case B even if user is logged on in the settings?
By the way, I'm using XCode 6.3 and Swift if that helps.
Thanks.
Turned out the problem was arising due to FBSDKShareDialog, using FBSDKShareButton will ALWAYS proceed with FacebookSDK's sharing function.
In order to do this, I made a workaround to manually trigger the FBSDKShareButton programmatically instead of making a FBSDKShareDialog.
let content:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com")
content.contentTitle = "Link Title"
content.contentDescription = "Link Description"
content.imageURL = NSURL(string: "Image Link")
//FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
let button:FBSDKShareButton = FBSDKShareButton()
button.frame = CGRectMake(0, 0, 0, 0)
button.shareContent = content
button.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
Related
I'm trying to add checkin functionality on my app. I got the place Id from admin panel and If user wants to checkin their they can do that through my app using the code below, but for some reason this code is not working only posting the link without taking the location, even this code can post quote as well but no location.
PS: The Facebook app is in development mode and the place id is valid as the same place id is working on android.
let content : ShareLinkContent = ShareLinkContent()
content.contentURL = URL(string: "https://www.google.com")
content.placeID = "493869400814446"
let dialog = ShareDialog(
viewController: self,
content: content,
delegate: nil
)
dialog.mode = .automatic
dialog.show()
In it's FAQ, WhatsApp explains how to create a new, prefilled message where the user can choose the contact to send the message to:
"To create a link with just a pre-filled message" from the FAQ Page here: https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app
The link looks like this: https://wa.me/?text=I%27m%20inquiring%20about%20the%20apartment%20listing (example from the FAQ Page).
However, since a few days this seems not to work anymore on iOS and Desktop (Android Phones seems not to be affected yet).
The link with a phone number (https://wa.me/123456789?text=The%20message%20to%20send) is working just fine. The workaround with just adding "0" as the phone number doesn't work either as whatsApp will throw an error that the contact could not be found.
Has anyone else run into the same problem? And found a soution / workaround?
Your URL seems to be wrong. You need to append URL path which is /send in your URL string. You seem to be adding the URLQueries right after the base URL. Also, use addingPercentEncoding for encoding.
guard
let urlString = "whatsapp://send?text=\(text)"
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let unwrappedUrl = URL(string: urlString) else {
return nil
}
I have successfully saved a CKShare URL to CloudKit, and I can see that the user is INVITED in the CloudKit Dashboard. My Mac app emailed the URL to that person, but when they click it, all they see it this screen on icloud.com:
Clicking OK makes everything disappear so all you see is the background on the web page.
My understanding is that the URL is supposed to open my Mac app where it will fire userDidAcceptCloudKitShareWith in my app delegate. But it does nothing.
Could this be because my app is in development and not in the Mac App Store yet? Do I need a custom URL scheme to get it to open my app?
Documentation on this stuff is pretty sparse. I'd love any help someone can provide.
I have since learned that you must specify a fallback URL for your CloudKit container. In cases where the app isn't installed (or isn't recognized, which seems to be the case when doing dev builds in Xcode like I am), CloudKit will forward share URL to somewhere you specify. They append the unique share ID to the URL so that you can process it on your own web page.
In the CloudKit dashboard, go to Environment Settings... and you'll see this popup:
I have it redirect to https://myapp.com/share/?id= and on my web page where it redirects to, I do a $_GET['id'] to grab the id. I then do another redirect to my application using a custom URL scheme and pass the share ID (e.g. myapp://abc123 where abc123 is the share ID).
In my app delegate, I receive the URL like this:
func application(_ application: NSApplication, open urls: [URL]) {
if let url = urls.first, let shareId = url.host{
fetchShare(shareId) //<-- sharedId = abc123
}
}
I then use CKFetchShareMetadataOperation to look up the URL of the share and CKAcceptSharesOperation to accept it like this:
func fetchShare(shareId: String){
if let url = URL(string: "https://www.icloud.com/share/\(shareId)"){
let operation = CKFetchShareMetadataOperation(shareURLs: [url])
operation.perShareMetadataBlock = { url, metadata, error in
if let metadata = metadata{
//:::
acceptShare(metadata: metadata)
}
}
operation.fetchShareMetadataCompletionBlock = { error in
if let error = error{
print("fetch Share error: \(error)")
}
}
CKContainer.default().add(operation)
}
}
func acceptShare(metadata: CKShareMetadata){
let operation = CKAcceptSharesOperation(shareMetadatas: [metadata])
operation.acceptSharesCompletionBlock = { error in
if let error = error{
print("accept share error: \(error)")
}else{
//Share accepted!
}
}
CKContainer.default().add(operation)
}
I think there are easier ways to work through this using NSItemProvider and NSSharingService, but I'm doing a lot of custom UI and wanted to have full control of the share workflow.
I hope this helps someone. :)
I am working on a project where I share video on Vimeo. In this My app open a video where user needs to press authorize button to authorize the app at Vimeo and to get access tokens. So, for this, my app opens safari and open Vimeo's site there. The user needs to press allow button then it has to come back again to the app. But I am not able to know what should be the call back url to make the Safari/Vimeo to come back to my app.
Please suggest your views regarding this.
You need to set a custom URL scheme for your app by editing your app's Info.plist. There's plenty of documentation about this on Apple's developer website. Here's an article that goes into detail: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
Then your website just needs to open a url that uses your app's url scheme (eg: myappscheme://do/something/cool?foo=bar). If your app cares about any data passed in to it via your website then implement the "application:openURL:sourceApplication:annotation:" method and inspect the NSURL passed in. You can read more about this in Apple's documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
You need to implement something called 'URL Scheme' to your app, which means register your app to a certain url, so it can be opened from.
1) You should add a row to your info.plist file.
2) You need to listen to the url in your app, and do what needed.
Google for more info...
To support a custom URL scheme:
Define the format for your app's URLs.
Register your scheme so that the system directs appropriate URLs to your app.
Handle the URLs that your app receives.
URLs must start with your custom scheme name. Add parameters for any options your app supports. For example, a photo library app might define a URL format that includes the name or index of a photo album to display.
an example is :
myphotoapp:albumname?name="foods"
myphotoapp:albumname?index=1
Register Your URL Scheme
click on project target and goto info page
in the info page expand URL Types section and hit the + button
fill fields with appropriate values.
Handle Incoming URLs
The system delivers the URL to your app by calling your app delegate's application(_:open:options:)method. you can useNSURLComponents` APIs to extract the components. Obtain additional information about the URL, such as which app opened it, from the system-provided options dictionary.
func application(_ application: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -> Bool {
// Determine who sent the URL.
let sendingAppID = options[.sourceApplication]
print("source application = \(sendingAppID ?? "Unknown")")
// Process the URL.
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let albumPath = components.path,
let params = components.queryItems else {
print("Invalid URL or album path missing")
return false
}
if let photoIndex = params.first(where: { $0.name == "index" })?.value {
print("albumPath = \(albumPath)")
print("photoIndex = \(photoIndex)")
return true
} else {
print("Photo index missing")
return false
}
}
If your app has opted into Scenes, and your app is not running, the system delivers the URL to the scene(_:willConnectTo:options:) delegate method after launch, and to scene(_:openURLContexts:) when your app opens a URL while running or suspended in memory.
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
// Determine who sent the URL.
if let urlContext = connectionOptions.urlContexts.first {
let sendingAppID = urlContext.options.sourceApplication
let url = urlContext.url
print("source application = \(sendingAppID ?? "Unknown")")
print("url = \(url)")
// Process the URL similarly to the UIApplicationDelegate example.
}
}
I need to share users posts from my iphone app to google+. I did facebook and twitter share.
Does google+ have an API for this? Does anyone have any examples?
Here is the link for the API of Google plus:
https://developers.google.com/+/api/
& here is the link where u can find help for sharing in google plus
http://code.google.com/p/google-api-objectivec-client/wiki/Introduction
For Swift 3.0
import SafariServices
then add the delegate
<SFSafariViewControllerDelegate>
use this below code in the share button
var urlComponents = URLComponents(string:"https://plus.google.com/share")
let queryItem = URLQueryItem(name: "url", value: "https://myexamplepagetoshare.com")
urlComponents?.queryItems = [queryItem]
let url = urlComponents?.url
let safariVC = SFSafariViewController(url: url!)
safariVC.delegate = self
self.present(safariVC, animated: true, completion: nil)
This is the simple G+ share that's available now.
The easiest way of sharing the posts on google plus is to first include its GPPShare.h file in xcode and then extend the .h file with GPPShareDelegate
And then write this code in the IBAction method
id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] shareDialog];
// This line will manually fill out the title, description, and thumbnail of the
// item you're sharing.
[shareBuilder setTitle:#"Share" description:#"sharing" thumbnailURL:[NSURL URLWithString:#"http://25.media.tumblr.com/tumblr_m9p3n1vJmZ1rexr16o1_400.jpg"]];
[shareBuilder setContentDeepLinkID:#"rest=1234567"];
[shareBuilder open];
and also implement GPPShareDelegate method which is helpful in order to detect the successful sharing
- (void)finishedSharing:(BOOL)shared
{ if (shared) {
NSLog(#"User successfully shared!");
} else {
NSLog(#"User didn't share.");
}
Right now they don't have any API I think.They are soon going to introduce .I hope help you.
But not now.
You use the Google+ share link:
https://developers.google.com/+/plugins/share/#sharelink
"The share link is intended for native client applications... and
others who may not be able to use the +1 or share button"
I integrated Google plus sharing. Please see this code. https://www.dropbox.com/s/o0bwtzgbpobsjkq/Share.zip?dl=0