Firebase dynamic link not working as expected with custom domain - android

I have example.com custom domain and i want to let invite members to groups inside the app with dynamic links.
I want to use app.example.com/ as prefix.
All libraries installed, team id on firebase for ios is defined and imported with new google services plist.
So my url i prepared to my desire is this (building this as shortlink app.example.com/SOMERANDOMTHING)
https://app.example.com/?link=https://example.com/joingroup?groupid=SOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
on iOS:
added to info.plist:
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://app.example.com</string>
</array>
Also added applinks:app.example.com to associated domains
And to URL Schemes, added com.myorganization.myapp
And my code on component did mount:
componentDidMount() {
var that = this
dynamicLinks().onLink((link) => {
that.handleDynamicLink(link)
})
if(Platform.OS == 'android') {
dynamicLinks().getInitialLink().then((link2) => {
if(link2) {
that.handleDynamicLink(link2)
}
Problems
on Android
When click link re-opening app from start and it calls
getInitialLink, onLink not working (Thats why i selected platform
for getinitiallink because on ios both functions working) .
Also when click link; no option like 'Open with MyApp' so link is
not associated with MyApp, after clicking browser decides link to be
opened with MyApp. (OK, it works but not cool)
If I add this to AndroidManifest:
<data android:host="app.example.com" android:scheme="http"/>
<data android:host="app.example.com" android:scheme="https"/>
this time link opening with my app and android recognizes link
belongs to MyApp but neither getInitialLink nor onLink works.
on iOS
onLink works, but its not transferring result to the app; its just transferring all link
https://app.example.com/?link=https://example.com/joingroup?groupid=SOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
instead of
https://example.com/joingroup?groupid=SOMEGROUPID
So im stuck on these problems, thanks for your assist

This is possible if you use a link as a parameter of another link. I suggest replacing this with the following
https://app.example.com/?link=https%3A%2F%2Fexample.com%2Fjoingroup%3Fgroupid%3DSOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
If you use JavaScript to create a link manually, you can use encodeURIComponent
const link = encodeURIComponent('https://example.com/joingroup?groupid=SOMEGROUPID');
const url = `https://app.example.com/?link=${link}&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp`;
console.log(url)

Related

How to redirect to the app store from a deep link if the app is not installed?

I'd like for users to be able to share a link (e.g. app.com/SKFLA - this is primarily because deep links on their own aren't clickable) via Facebook etc. When clicked, this redirects to a deep link app://SKFLA. If the app is installed, this opens the app - this is all working fine so far. But if the app isn't installed, I'd like to open the app store on the relevant page. Is this achievable? Thanks!
You need UNIVERSAL LINKS
Please check
IOS https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
Android
https://developer.android.com/training/app-links/
It might also require some extra server-side setup.
Not sure about native behavior.
We used third-party service like https://branch.io/deepviews/.
There is a bunch of similar services.
If someone is still stuck in this issue and needs easiest solution, you will love node-deeplink
1.) If app is installed: Calling an app through deep linking will always call componentDidMount of root component. So you can attach a listener there. Like:
Linking.getInitialURL()
.then(url => {
if (url) {
this.handleOpenURL({ url });
}
})
.catch(console.error);
Linking.addEventListener('url', this.handleOpenURL);
handleOpenURL(event) {
if (event) {
console.log('event = ', event);
const url = event.url;
const route = url.replace(/.*?:\/\//g, '');
console.log('route = ', route);
if(route.match(/\/([^\/]+)\/?$/)) {
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (routeName === 'privatealbum') {
Actions.privateAlbum({ albumId: id });
}
}
}
}
2.) If app is not installed: Just set up a route in your server and node-deeplink package will handle the bridging between web browser to app store when a app is not installed in your mobile.
By this, both the cases will be handled without any struggle

How can I access the values passed into my app via a custom url scheme from within my C# code?

I'm working on a Xamarin Forms application. It has an Entry field for the visit code on the initial page. I need to extend its functionality so that the application will open when a custom url scheme myscheme://visitcode is encountered, and the Entry will have its Text value prepopulated with the value of visitcode.
I've had success with getting the application to launch.
I added my scheme to the info.plist file in my iOS project, and it properly launches the app when I click on my custom url scheme in Safari on an iPhone.
I added the following line above my MainActivity in my Droid project:
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "myscheme")]
It properly launches the app when I click on my custom url scheme in Chrome on an Android phone.
The only remaining obstacle is to retrieve the value and populate the Entry field with it.
Can someone help me?
Note: I haven't tested this yet, so make sure your app lifecycle and the place where you handle the events are matching the Xamarin.Forms app lifecycle. That is, make sure Xamarin.Forms.Application.Current is not null. If it is, reshuffle your code to work around that.
For iOS, you have to override OpenUrl in your AppDelegate.cs:
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation);
and in Android, you handle that in your MainActivity.cs, in your OnCreate or any other method used as entry point:
var intent = Intent;
var uri = intent.Data;
That should allow you to retrieve the parameters of the url.
You then can retrieve the current Xamarin.Forms Application object, by doing:
var myapp = Xamarin.Forms.Application.Current as MyApplication;
Now, it's up to you to retrieve the right entry, or it's view model, or a service or whatever to connect the dots.
There is a component within the Xamarin store that handles this for you:
http://components.xamarin.com/view/rivets
This will remove the lengthy code requirements in building native implementations.

Is it possible to implement deep links from website to native app?

I have three buttons on my website, that link to Facebook, Twitter & vk.com pages. I want to open native app, if it is installed on user device. Otherwise, I want URL fallback to be opened.
First of all, I tried to use native app schemes directly with deep-link.js plugin. But, when I tried to open native app URL scheme, when native app was not installed, Safari has shown an error, but opened URL fallback page finally. Default Android browser said that he does not know how to handle such URL scheme:
<a class="btn btn-primary" href="https://www.facebook.com/warpcompany" data-app-ios="fb://profile/838619192839881" data-app-android="fb://page/838619192839881">Facebook</a>
Then I tried to use App Links "standard", that that has so much promotion from Facebook. I even tried to use their hosted app links, to make sure I've generated everything right way. It does not work, it always redirect to website fallback. You can easily test it by yourself from https://fb.me/746134728830806
Is it possible to provide deep link on website, that will open native app without errors at least in default os browsers, or fallback silently to URL?
It is still possible, but on newer versions of the Android default browser you have to use intents instead of just trying to open the deep link. For example replace your fb://page/838619192839881 with
intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;end
This will fallback to Google play by default, but you can override the fallback adding a S.browser_fallback_url:
intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;S.browser_fallback_url=http%3A%2F%2Fwww.facebook.com%2F;end
The fallback should be url encoded.
Of course you'll have issues if the user is not on an Android phone or with an old version of the default browser (or strange browser). You can setup a bunch of conditions and replace your HTML with the correct code for each case.
The accepted answer will only work on Chrome v28 and default browsers for Android 5.0. If you want this to work on other browser like Facebook/Twitter webviews, Firefox, UC and older default browsers than 5.0, you'll need to use some code that's a little more complicated.
Add this function to your JS snippet:
var openSesame = function() {
var method = 'iframe';
var fallbackFunction = function() {
if (method == 'iframe') {
window.location = "market://details?id=com.facebook.katana";
}
};
var addIFrame = function() {
var iframe = document.createElement("iframe");
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.src = "fb://page/838619192839881";
document.body.appendChild(iframe);
};
var loadChromeIntent = function() {
method = 'intent';
document.location = "intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;end";
};
if (navigator.userAgent.match(/Chrome/) && !navigator.userAgent.match("Version/")) {
loadChromeIntent();
}
else if (navigator.userAgent.match(/Firefox/)) {
window.location = "fb://page/838619192839881";
}
else {
addIFrame();
}
setTimeout(fallbackFunction, 750);
};
Then your button will look like this:
Open the App
Or you can use a service like branch.io which does exactly what you're looking for automatically.
Yes it is! Have a look to this training:
https://developer.android.com/training/app-indexing/deep-linking.html
Is this the information you needed? lmk

Cannot get the new AppLinks to work on iOS or Android

Latest Update Below at Update #5
I'm trying to implement AppLinks for BOTH my iOS AND Android apps : http://applinks.org
I've done the following:
setup a custom url scheme for my app: inacho://
Setup in my App Delegate: - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
Add meta tags to my website at http://www.nachorater.com :
<meta property="al:ios:app_store_id" content="581815579"/>
<meta property="al:ios:app_name" content="iNacho" />
<meta property="al:ios:url" content="inacho://default" />
I've verified that the url scheme works great by typing in a link like inacho://default into Notes and clicking the link it creates. Wa-la! It opens my app.
But when I try clicking on a link to www.nachorater.com from Facebook or Quip, neither app automatically seems to take any notice that the site has these app links setup and it just loads the website in their browser(s) instead of trying to open my app.
Has anyone got this working?
Update:
I had an issue with some meta tags not being in the < head > portion of my templates and I fixed it.
Now the link: http://www.nachorater.com from the iOS Facebook app adds a nice little popup that lets you open the url in the iNacho app like so:
But my links to my dynamic reviews do not seem to be working, yet the Debug app that Ming pointed out shows that the meta tags look correct for them.
For example, http://www.nachorater.com/getReview?reviewID=6396169718595584
meta tags when debugging with https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.nachorater.com%2FgetReview%3FreviewID%3D6396169718595584 :
Update #2:
I posted a new nacho review link to my iNacho Facebook timeline and then tried to click on it from the Facebook Mobile app.
It started to load the page and popped up the handy indicator that lets you open the app in iNacho but then once the page loaded, the indicator went away (before I could click it).
Update #3:
From the Facebook app, I can now trigger an inacho URL for my reviews BUT it's ONLY if I click the little popup to open in iNacho before it disappears. If I let the page completely load in Facebook's built-in web view, the little popup disappears still.
Is this a problem with Applinks? Or a problem with the Facebook app? Or by design and why?
Update #4:
I may know what the problem is. The review page in turn loads up a dynamic image for the nacho review. So by loading the page, it has an img src tag that points to a dynamic url that loads the image. Is this being mistaken for a 'redirect' action of some sort?
Example of img tag (rendered): <img width="300" src="/getReviewImage?imageID=6125868501958656"></img>
Note: There are a bunch of other scripts/ajax that gets loaded dynamically too though (Facebook and twitter widgets and the like).
Is this a bug in AppLinks or the Facebook Mobile app? Shouldn't it not care about background loading objects like ajax and dynamic images?
Update #5
7/15/14 - This is still happening with latest Facebook app. When I click a link from my iNacho Facebook page to my iNacho website, it pops up the option to open it in the app for a split second before the page finishes loading. Then it hides it.
As for the twitter app, it does not even give me the popup for a split second. It doesn't seem to recognize the link is appslink enabled at all.
Quip on the other hand, I pasted a nacho link in and the first time I clicked on it, it went to its built-in safari with no option to open in my app. BUT the second time I clicked it, it directly opened my app instead.
Summary: So far, it seems like maybe some apps are implementing the AppLinks Navigation portion incorrectly or something. Quip seems to work but even Facebook's own app seems like it's not working.
I was having the same problem with AppLinks and decided to just forego them altogether and just use facebook's app link host: https://developers.facebook.com/docs/applinks/hosting-api
My app is really mobile only, and I misunderstood how AppLinks worked at first. I thought I could just put the al_ios_* meta tags on a single, universal web page but this is wrong. There would need to be a separate page for every piece of content on my site, and each one of those pages needs to have its own AppLinks meta tags to send a URL for that specific content back to my app.
When I was doing it wrong, when I tapped on my OpenGraph story in facebook, it would open my site in the web browser and there was an action icon in the bottom toolbar that I could tap and have the option to open my app. Or I would have to precision-tap the name of my app in the OpenGraph story. Either of those fast-switch to my app, but the URL would not be specific to the content I want my app to navigate to. Also, both of those options suck -- I just want to tap anywhere on the story and go straight to my app, which is why we're all here.
The solution
I am going to use an OpenGraph story with the share dialog as an example.
First, you need to create a hosted app link on your server, not in the app. Before creating your OpenGraph story or whatever is being shared, make a call to your server to accomplish 2 things:
1.) Make an API call to create a new facebook app link, which will give you back an ID
2.) Use that ID to make a 2nd API call to get the URL to your hosted app link
This has to be done on the server because these API calls require an app access token, not a user access token. This token has app level permissions, not user level permissions. You cannot and should not store your facebook app secret anywhere in your mobile application because someone could decompile your app and make changes to your facebook app. No good. Use your server because it can safely know your app secret.
My server side is in PHP so here is an example of how to accomplish this. Dealing with the API wasn't a particularly pleasant experience, so I'll share in hopes that it helps someone else with formatting the requests:
# create a new facebook app link using cURL
$metadata = <what to handle in AppDelegate application:openURL:sourceApplication:annotation>;
$url = "https://graph.facebook.com/v2.1/app/app_link_hosts";
$ch = curl_init($url);
# create form post data
$deepLinkURL = "<myApp>://" . $metadata;
$iosArray = json_encode(array(array("url" => $deepLinkURL,
"app_store_id" => <appStoreId (number)>,
"app_name" => "<myAppName>")
)
);
$webFallbackArray = json_encode(array("should_fallback" => false));
$formQuery = http_build_query(array("access_token" => "<appId>|<appSecret>",
"name" => $metadata,
"ios" => $iosArray,
"web" => $webFallbackArray)
);
# options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formQuery);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# get response
$responseJson = curl_exec($ch);
curl_close($ch);
# decode response from facebook
$jsonResponse = json_decode($responseJson, true);
$appLinkId = "";
# get appLinkId
foreach ($jsonResponse as $key => $val) {
# get status
if($key == "id") {
$appLinkId = $val;
}
}
# if response is good, need to request canonical URL from appLinkId
$errorMessage = "";
$canonicalUrl = "";
if(!empty($appLinkId)) {
# create another instance of cURL to get the appLink object from facebook using the ID generated by the previous post request
$getAppLinkUrl = "https://graph.facebook.com/" . $appLinkId;
$ch2 = curl_init();
# cURL options
$queryString = http_build_query(array("access_token" => "<appId>|<appSecret>",
"fields" => "canonical_url",
"pretty" => true)
);
curl_setopt($ch2, CURLOPT_URL, $getAppLinkUrl . "?" . $queryString);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
# get response
$urlResponseJson = curl_exec($ch2);
curl_close($ch2);
# decode response from facebook
$urlJsonResponse = json_decode($urlResponseJson, true);
# parse response to get canonical URL
foreach ($urlJsonResponse as $key => $val) {
# get canonical URL
if($key == "canonical_url") {
$canonicalUrl = $val;
}
}
# check for result
if(empty($canonicalUrl)) {
$errorMessage = "Unable to retreive URL.";
}
} else {
$errorMessage = "Unable to publish appLink.";
}
# encode response back to your app
if(empty($errorMessage)) {
$response = json_encode(array("result" => "success",
"canonical_url" => $canonicalUrl));
} else {
$response = json_encode(array("result" => "failed",
"errorMessage" => $errorMessage));
}
#send response back to your app
Back in your app, once you confirm a good response, put the canonical URL you get back as the url parameter in [FBGraphObject openGraphObjectForPostWithType: below. Now when you click on your story in the facebook app, it will go straight to your app. No web nonsense.
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
// Create an object
id<FBGraphObject> object;
// set shareDialog parameters
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = #"<myApp>:<myAction>";
params.previewPropertyName = #"<key>";
object = [FBGraphObject openGraphObjectForPostWithType:#"<myApp>:<myObject>"
title:<title>
image:<urlToPic>
url:<fb.me/xyz canonical URL>
description:<someDescription>];
[action setObject:object forKey:#"<key>"];
etc...
When I was working on my app, Sweep, I put a pay/share wall after a certain amount of time spent in the app. I faced the same problem where AppLinks really sucked at actually linking off of Facebook, despite the promise. Based on this problem, I built a service called branch.io that hosts the links for me, plus automatically inserts the correct AppLinks metatags for Android/iOS. The links actually work as expected, as crazy as that is. It uses a combination of client side JS with the AppLinks to make them properly redirect in every webview and native browser
Here's a high level guide to creating the share links on iOS:
To get started, you just need to configure the location of your app in either store on the dashboard at dashboard.branch.io. Once it's all setup, you get your Branch app key.
pod "Branch" or you can clone the open source repo here:
https://github.com/BranchMetrics/Branch-iOS-SDK
Add the Branch key to your plist file as a String with the key 'branch_key'
Add the following code to your AppDelegate in the appropriate methods
In the didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// your other init code
Branch *branch = [Branch getInstance];
[branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { // previously initUserSessionWithCallback:withLaunchOptions:
if (!error) {
// params are the deep linked params associated with the link that the user clicked before showing up
// params will be empty if no data found
// here is the data from the example below if a new user clicked on Joe's link and installed the app
NSString *name = [params objectForKey:#"user"]; // returns Joe
NSString *profileUrl = [params objectForKey:#"profile_pic"]; // returns https://s3-us-west-1.amazonaws.com/myapp/joes_pic.jpg
NSString *description = [params objectForKey:#"description"]; // returns Joe likes long walks on the beach...
// route to a profile page in the app for Joe
// show a customer welcome
}
}];
}
In the openUrl for handling URI calls:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// pass the url to the handle deep link call
// if handleDeepLink returns YES, and you registered a callback in initSessionAndRegisterDeepLinkHandler, the callback will be called with the data associated with the deep link
if (![[Branch getInstance] handleDeepLink:url]) {
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
}
return YES;
}
Lastly, to create the hosted links, it's very simple. You just need to call getShortUrl to dynamically create one. You can put as many keys and values in the links as possible (to be retrieved in the initSession callback)
You can put this snippet anywhere you want to create a link:
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:#"Joe" forKey:#"user"];
[params setObject:#"url.to.picture/mypic.png" forKey:#"profile_pic"];
[params setObject:#"Joe likes long walks on the beach..." forKey:#"description"];
// Customize the display of the link
[params setObject:#"Joe's MyApp Referral" forKey:#"$og_title"];
[params setObject:#"url.to.picture/mypic.png" forKey:#"$og_image_url"];
[params setObject:#"Join Joe in MyApp - it's awesome" forKey:#"$og_description"];
// Customize the redirect performance
[params setObject:#"http://myapp.com/desktop_splash" forKey:#"$desktop_url"];
Branch *branch = [Branch getInstance];
[branch getShortURLWithParams:params andCallback:^(NSString *url, NSError *error) {
// show the link to the user or share it immediately
}];
Android is very similar in method calls and functionality and can be found on the site.
sorry if my answer is not exactly what you expect but just to share what we did on our websites and apps.
For instance, I know we had to add more tags to make it works with twitter cards and here is the list of the meta properties we have in our pages:
meta property="twitter:card" content=""
meta property="twitter:title" content=""
meta property="twitter:description" content=""
meta property="twitter:image:src" content=""
meta property="twitter:app:id:iphone" content=""
meta property="twitter:app:name:iphone" content="Marmiton"
meta property="twitter:app:url:iphone" content=""
meta property="twitter:app:id:googleplay" content=""
meta property="twitter:app:name:googleplay" content=""
meta property="twitter:app:url:googleplay" content=""
and the metha you also have:
meta property="al:iphone:app_store_id" content=""
meta property="al:iphone:app_name" content=""
meta property="al:iphone:url" content=""
meta property="al:android:package" content=""
meta property="al:android:app_name" content=""
meta property="al:android:url" content=""
we also have the facebook opengraph meta defined such as fb:app_id. I mention that because when you receive the deeplink in your app, you also have the facebook app id in the applinks link.
And from what we tested:
facebook does not open the deeplink directly on iOS whereas Android gives you the app choice. It sometimes shows up the blue popup at the bottom of the screen and sometimes you just have a link added in the actionsheet you have when you tap on the share button in the facebook (safari) webview (only at first load)-> this presentation of the link depends on how the content was shared on facebook.
twitter add a link to the app inside the card on iOS.
Don't know what I can add more.
Hope it helps a bit.

Titanium - Facebook module doesn't using native login

I'm trying to implement facebook login to the app I'm trying to develop with Titanium,
and when I'm clicking on "connect" button its shows me a dialog that looks like that:
Its looks like a web-app facebook login and not as native should look like. I want it to be like this:
So, how can I make this module use the native login dialog instead of this web style dialog?
In order to use the iOS native facebook login, you have to:
use the new facebook module require('facebook'), the old one is deprecated
set forceDialogAuth = false;
make sure the bundle id of your app is also set in your facebook app
Set the facebook app id in tiapp.xml
move the Info.plist to the root folder of your app and provide the facebook id and url scheme there (With the new SDKs you can do this in tiapp.xml, I will give some examples here in a minute)
The images you have posted are the fallback solution, that will happen if
the user has not activated the facebook login/facebok app on the device
the user has an iOS version prior to the native facebook login
you run your app in the simulator
This is how I use the native iOS login, step-by-step:
1. Create a facebook app
In order to use the native iOS facebook login, you have to create a facebook app at developers.facebook.com. Copy your app id to the text-editor, we will need it later.
2. Set up your facebook app
Enable the 'Native iOS app' integration at the Basics section.
(1) Enter the bundle id you are using for your app, the same you have set in tiapp.xml
(2) Activate Facebook-login if you want facebook to launch your app from bookmarks etc.
(3) Optional: for sharing your facebook id accross multiple apps. We will use this url scheme in the Info.plist as well.
3. Set up tiapp.xml
Go to Titanium Studio and open the tiapp.xml (typically the last file in your apps directory). There are two tabs in the lower left corner. We will need Overview first. Make sure that your Application Id matches the one you have entered in your facebook app. Click at the + of the modules and add Appcelerators own facebook module, which is installed by default. It should appear in the list below.
Still in tiapp.xml, click the tiapp.xml tab, and add the following: <property name="ti.facebook.appid">XXXXXXXX</property>with the Xs being your facebook app id, obviously.
4. Copy and edit the Info.plist file
In Finder, navigate to your apps root folder. From here, go to build > iphone. You should see the Info.plist here. Copy it and paste it to the root folder of your app. Open it with the text editor of your choice. Add FacebookAppID and FacebookDisplayName to the file and replace the placeholder values with your own. This might not be necessary, but I use it and it works, just to be on the safe side ;) Look for CFBundleURLTypes and edit it to look like below, with test being the URL scheme of your app, you have set it in your facebook app before. This will allow your app to be opened from Safari as well, by entering test://. Please note the fb within the CFBundleURLSchemes array, this has to prefix your facebook app id, unlike all other fields before.
<key>FacebookAppID</key>
<string>XXXXXXXXXXXXX</string>
<key>FacebookDisplayName</key>
<string>Your facebook app name</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>test</string>
<key>CFBundleURLSchemes</key>
<array>
<string>test</string>
<string>fbXXXXXXXXXX</string>
</array>
</dict>
</array>
Please note: with the latest SDKs, these settings can be set in tiapp.xml as well, but since I have not done it yet, this example uses the Info.plist
5. Using the facebook module
I do not use the standard facebook button often, as it can not be customized enough. So assuming you have a login button called loginButton and a logoutButton called logoutButton we hook them up to our facebook module:
// The module we have added to our project via tiapp.xml before
var facebookModule = require('facebook');
// We can read the facebook app id from tiapp.xml
var FACEBOOK_APP_ID = Ti.App.Properties.getString('ti.facebook.appid');
// Set the app id
facebookModule.appid = FACEBOOK_APP_ID;
// Do not force a facebook html popover but use the native dialog if possible
facebookModule.forceDialogAuth = false;
// Add an event listener to the facebook login event
facebookModule.addEventListener('login', facebookLoginHandler);
// Also add an event listener to the logout event
facebookModule.addEventListener('logout', facebookLogoutHandler);
// The event listener of our login button
loginButton.addEventListener('click', function() {
facebookModule.authorize();
});
// The event listener of our logout button
logoutButton.addEventListener('click', function() {
facebookModule.logout();
});
// The facebook login event handler
function facebookLoginHandler(e) {
if (e.success) {
// Success!
} else if (e.error) {
// Error!
} else if (e.cancelled) {
// cancelled by user
}
}
// The facebook logout handler
function facebookLogoutHandler(e) {
if (e.success) {
// Success, clear the facebook browser cookies so someone else
// can login later, if the browser fallback is used
var client = Titanium.Network.createHTTPClient();
client.clearCookies('https://login.facebook.com');
} else if (e.error) {
// Error!
}
}

Categories

Resources