Where exactly should I put the call to [FBSettings publishInstall:appId] - ios

I'm looking at integrating support for tracking Facebook's new mobile app ads.
I've read the tutorial here:
https://developers.facebook.com/docs/tutorials/mobile-app-ads/
It says:
Include the following code to be executed when your app opens for the first time by user
[FBSettings publishInstall:appId];
So the first question is - where do I put this so that it only invokes the call if the install was driven from Facebook? I don't want FB to get credit for someone who found my app themselves on the app store.
Do I need to manually track whether or not I've called the publishInstall before for this specific user? (The preamble sentence implies this - but the SDK documentation for publishInstall implies otherwise).
And even more confusing is that the SDK FBSettings reference includes shouldAutoPublishInstall which defaults to YES. This would suggest that I don't need to do anything other than have the SDK integrated. So why does the tutorial not mention this as an option?
I assume that the appId is the associated Facebook appId (as opposed to the App Store App ID). This is also not clear from the documentation.

I browsed the sources of facebook iOS SDK, and it seems that guide is wrong.
You are right, that autoPublishInstall is set to YES by default, which means we don't need to invoke [FBSettings publishInstall:appId]; manually. AppId is indeed the facebook app id.
When you invoke openActiveSessionWith.... method, it initializes FBSession with
initWithAppID:permissions:defaultAudience:urlSchemeSuffix:tokenCacheStrategy: which contains in the end [FBSettings autoPublishInstall:self.appID];
+ (void)autoPublishInstall:(NSString *)appID {
if ([FBSettings shouldAutoPublishInstall]) {
dispatch_once(&g_publishInstallOnceToken, ^{
// dispatch_once is great, but not re-entrant. Inside publishInstall we use FBRequest, which will
// cause this function to get invoked a second time. By scheduling the work, we can sidestep the problem.
[[FBSettings class] performSelector:#selector(publishInstall:) withObject:appID afterDelay:FBPublishDelay];
});
}
}
So technically it should report the install out of the box (if I'm not missing something). I'm going to play with it a little more today to see if it works as expected and update answer with results.

Just put it at -[application:didFinishLaunchingWithOptions].
Not all of the apps want to integrate the Facebook login. They only want the feature "mobile app install ads". For these kind of app, they should invoke +[FBSettings publishInstall:appId] manually. On the other hand, if your app has already integrated facebook login, you can assume that the FB sdk has published the installation.

If we just have to put
[FBSettings publishInstall:appId];
manually in
-[application:didFinishLaunchingWithOptions]
how will I identify which install happened from facebook? I don't want FB to get credit for someone who found my app themselves on the app store.

put the code in Appdelegate DidbecomeActive method
- (void)applicationDidBecomeActive:(UIApplication *)application
hope this help :)

Related

Does Facebook Deferred Deep Linking on iOS work, and how to test it before publishing the app on Store?

I have a problem with Facebook Deferred Deep Linking on iOS. DEEP LINKING WORKS, BUT DEFERRED DEEP LINKING DOESN'T WORK. I have read a lot about this problem and still cannot find the solution.
I have set up deep linking and it works. When I also try to test deep linking on App Ads Helper and click on "Test deep link", enter deep link and click on "Send notification", I receive a notification on Facebook which opens my app, and this deep linking works. But, when I click "Select Deferred", I don't receive anything. I try to delete app and reinstall it, but [FBSDKAppLinkUtility fetchDeferredAppLink:...]; method doesn't get any deferred deep link after new install.
[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
if (error) {
NSLog(#"Received error while fetching deferred app link %#", error);
}
if (url) {
[[UIApplication sharedApplication] openURL:url options:#{} completionHandler:^(BOOL success) {
}];
}
}];
In this example, url is always nil.
Note: I still don't have app on Store, so I entered a Apple Id of another application. Even if I had my own app on Store, how could I test deferred deep linking without publishing app on Store?
Also, I have read on Facebook documentation that:
Beginning with iOS 10, iOS doesn't support deferred deep linking, so you can't open content other than the starting screen once people have installed the app. (Source)
So, I am not sure if this is even possible.
Also, I have read another articles on Stackoverflow, but there are not answer that I am looking for, i.e. they look incomplete, or I just don;t see the answer between the lines:
How to use facebook deferred deep linking feature for new installs
and to test the same before publishing iOS App to appStore? -> Answers to this question aren't what I am looking for:
If you want to verify deferred links then check 'Send Deferred' in the dialog.
So, after doing this you need to uninstall the app(if already present) and then install again from the app store. The device in which you will be testing this should have facebook app installed and logged in with the account from which you had sent the "deferred deep link request" from app-ads helper.
Now when you open your app, you should bee able to see your deferred deep link functionality working.
This doesn't work, so that's why I am asking this question.
Also, I have found that I could use Tune SDK for deferred deep linking:
...this is not a problem with the iOS 10 operating system itself. Deferred deep linking works just fine for iOS 10 using the TUNE SDK. (Source)
Also, I have found that I could use Branch.io for deferred deep linking:
With Branch, you get all the basic routing of a Universal Link plus the deferred deep linking and install attribution for the new user acquisition flow. (Source)
I haven't tried Tune and Branch.io. I would like to use Facebook ads and perform deferred deep linking without third party solutions. Is it possible with Facebook, and how to test deferred deep linking for Facebook on iOS?
It worked for us after resetting advertising identifier. Maybe internally they are preventing attribution in the same app twice if it is the same advertising identifier. So go to settings and reset your advertising identifier before testing. Also make sure the phone has not opted out of tracking.
For me, the answer was in my iPhone settings. I had "Limit Ad Tracking" enabled. I don't have much documentation proof that this was causing the issue but after changing it, it is now working. It's worth testing it yourself.
On your iPhone go to: Settings -> Privacy -> Advertising (at the bottom of the page)
There you should ensure that "Limit Ad Tracking" is set to off.
You should then recieve a URL if you have your app URL Scheme correctly set (see here if not) code which for swift should look like this:
AppLinkUtility.fetchDeferredAppLink { [weak self] (url, error) in
guard let self = self else {return}
if (url != nil) {
} else if error != nil {
print("Error: \(error!.localizedDescription)")
}
}
To test the deferred links, you can go here.
A bit late, but per your comment on the previous answer: Once you receive the message:
The link has been queued and is pending you doing a first app launch on your device. This means you need to delete the app, then re-install and open your app. Please first verify your app can handle deferred deep linking by checking the iOS and Android setup information located above.
Delete the application from your device
Open Facebook notifications from your device, you should have a deeplink notification
Selecting the deeplink notification should direct you to the appropriate app store to install the application again
Once installed, launching the application should trigger the intended 'Deferred' deep link
For deferred deep link to work, you also need to be logged in on the Facebook app. The ads helper tool: https://developers.facebook.com/tools/app-ads-helper/ knows your logged in user id on facebook.com. Facebook then uses this info to match your id, the app and the device information and returns an appLink back to your app if so.
Unfortunately, that's not possible on simulator given the limitation to install other apps like Facebook.
Your only option is to use a real device and build your XCode project on it. Make sure you have Facebook installed and that you are logged in with the same user as on your desktop web browser.
If you are running Facebook ads with Deep linking enabled, you can test deferred deep linking setup here: https://developers.facebook.com/tools/app-ads-helper/
You will need to select your app, then you should be able to access the deep-link tester at the bottom of the page (in which you can also select deferred)
Additional info:
So you need to deploy the app to the store? – locoboy Aug 7 '15 at 16:38
For testing Deep Link or Deferred Deep Link as they said before me:
deploy to store not required, use FB Ads panel for testing
check just in case statistic for app installs (not equal zero) - may be AppEvents (automatically logged) doesn't work correct (keep in mind, in the calculation of statistics, there may also be a delay)
Install Facebook application for your device, auth in using the same profile that you use to send notifications (run FB app in background)
Select both 'Send Notification' and 'Send Deferred' check marks (or check only 'Send Deferred' - results will available after manual app reinstall, and don't forgot trigger FBSDKAppEvents activateApp)
Example after successful sending
The main objective - after sending the message you will see it in Facebook! app notifications, with logo + text "Tap to launch your deep link"
Tap on notification

Is there a way to recognize, that the app was installed thru firebase dynamic link in didFinishLaunchingWithOptions?

I am implementing firebase dynamic links in my iOS app and I can already parse the link, redirect to AppStore etc. Now I want to distinguish the first run of the app, when user installs it from the dynamic link - I want to skip the intro and show him the content that is expected to be shown.
Is there some parameter, that I could catch in application(_:didFinishLaunchingWithOptions:) so I could say that it was launched thru the dynamic link?
The method application(_:continueUserActivity:userActivity:restorationHandler:) is called later, so the intro is already launched.
This case is difficult to test, because you have to have your app published on the AppStore.
You actually don't need to have the app published in the App Store for this to work — clicking a link, closing the App Store, and then installing an app build through Xcode (or any other beta distribution platform like TestFlight or Fabric) has exactly the same effect.
According to the Firebase docs, the method that is called for the first install is openURL (no, this makes no sense to me either). The continueUserActivity method is for Universal Links, and is only used if the app is already installed when a link is opened.
I am not aware of any way to detect when the app is opening for the first time after install from a 'deferred' link, but you could simply route directly to the shared content (skipping the intro) whenever a deep link is present. If a deep link is NOT present, show the regular intro.
Alternative Option
You could check out Branch.io (full disclosure: I'm on the Branch team). Amongst other things, Branch is a great, free drop-in replacement for Firebase Dynamic Links with a ton of additional functionality. Here is an example of all the parameters Branch returns immediately in didFinishLaunchingWithOptions:
{
"branch_view_enabled" = 0;
"browser_fingerprint_id" = "<null>";
data = "{
\"+is_first_session\":false,
\"+clicked_branch_link\":true,
\"+match_guaranteed\":true,
\"$canonical_identifier\":\"room/OrangeOak\",
\"$exp_date\":0,
\"$identity_id\":\"308073965526600507\",
\"$og_title\":\"Orange Oak\",
\"$one_time_use\":false,
\"$publicly_indexable\":1,
\"room_name\":\"Orange Oak\", // this is a custom param, of which you may have an unlimited number
\"~channel\":\"pasteboard\",
\"~creation_source\":3,
\"~feature\":\"sharing\",
\"~id\":\"319180030632948530\",
\"+click_timestamp\":1477336707,
\"~referring_link\":\"https://branchmaps.app.link/qTLPNAJ0Jx\"
}";
"device_fingerprint_id" = 308073965409112574;
"identity_id" = 308073965526600507;
link = "https://branchmaps.app.link/?%24identity_id=308073965526600507";
"session_id" = 319180164046538734;
}
You can read more about these parameters on the Branch documentation here.
Hmm... as far as I'm aware, there's not really anything you can catch in the application:(_:didFinishLaunchingWithOptions) phase that would let you know the app was being opened by a dynamic link. You're going to have to wait until the continueUserActivity call, as you mentioned.
That said, FIRDynamicLinks.dynamicLinks()?.handleUniversalLink returns a boolean value nearly instantly, so you should be able to take advantage of that to short-circuit your into animation without it being a bad user experience. The callback itself might not happen until several milliseconds later, depending on if it's a shortened dynamic link (which requires a network call) or an expanded one (which doesn't).

"Login cancelled by player" callback in facebook api for Unity IOS (only if you have facebook app in device)

I am using unity facebook api 4.3.6 for ios. Its working perfectly fine if I don't have #facebookapp in my device. Once I download it and try login, it takes me to #facebookapp and redirect again to my game with callback
FB Login callback : {"is_logged_in":false, "user_id":"", "access_token":""}
Login cancelled by player
This happens only if I have facebook app downloaded! I think its some how cache issue but not sure exactly what is it. Any luck?
I believe this is not connected with Unity.
Here is few reasons I faced
You need to ask read and write permissions separately. Wait until you get read permissions than send request for write permission.
Make sure your app is allowed to login ( if you have FB app installed on your device )
Make sure you have your app bundle identifier added to developer.facebook.com
Here is what helped me fixed that problem with Unity Facebook-Android.
setting the sandbox mode ON:
Go to https://developers.facebook.com/apps
Select the respective app from the drop down.
Go to 'Status & Review' from the table in the left side of the page.
Do you want to make this app and all its live features available to the general public? - Select switch to set YES/NO value.
if the ON/OFF button is disable, please go back to Settings and enter a valid email address.
I understood why when the device is installed a facebook app, my app can't login facebook.
First : software OpenSSL create keyhass wrong. I have downloaded OpenSSL from here : http://code.google.com/p/openssl-for-windows/downloads/list , and it creates keyhash wrong.
I have used other OpenSSL sofware, you can download it here : https://www.dropbox.com/sh/t6tt44dc2nm6vza/6mp1W74GiZ , it is create keshash right.
Second: In class FacebookAndroidUtil.cs , line 62, you add System.Environment.GetEnvironmentVariable("HOMEDRIVE") before System.Environment.GetEnvironmentVariable("HOMEPATH"). Facebook SDK requires a file debug.keystore in : C:\Users\UserName.android\debug.keystore.
If the Unity Editor, Edit Setting Facebook has yet to create android debug hash key. Then use the Eclipse Software, create and run onr any project. Eclipse will generate a debug.keystore. If it is't create in folfer : C:\Users\UserName.android\debug.keystore , then find it, coppy and paste into C:\Users\UserName.android\debug.keystore
Third: publish your app in Facebook, so be sure it is:"This app is public and available to all users".

FaceBook IOS SDK - GitHub

I start writing a simple app to use FaceBook IOS SDK from GitHub.
I have a few questions about it:
Is there a better documentation about those Delegate .. functions ? I cannot find those except the ones in DemoApp in the package
In the DemoApp, fbDidLogin, fbDidNotLogin and fbDidLogout are never called ... even a dialog is shown and I typed in username and password for logging in
I finished my application with FaceBook SDK.Therefore, I can answer my own questions now.
1) Developer can follow the DemoApp OR can visit http://thinkdiff.net/facebook/how-to-develop-facebook-application-for-iphone/ for more information
2) fbDidLogin, fbDidNotLogin and fbDidLogout would only be called IF inline Dialog box (for FaceBook) is used. Those delegate functions won't be called IF FaecBook app or Safari browser is used instead

Facebook facebook-ios-sdk and graph api is not working

I am using the official facebook ios sdk in my app (https://github.com/facebook/facebook-ios-sdk)
It was all working fine. I was able to log in, pull all my info from Facebook, post things on my wall. Do all those regular stuff that you do...
But since last night, it appears to be broken. When the login window appears and the user logs in, instead of getting the authkey and getting a callback. The login window directs users to facebook.com.
Did anyone else notice the problem? Is there any fix to it or we just assume that the graph API is broken right now and wait?
I assume Facebook were just having a problem. If you had it working & did not change the code then the issue is elsewhere?
In general it's a pain to get working so the following is a brief hint to anyone who is stuck.
Having spent 2 days getting this working I recommend (assuming you have registered an app with Facebook) :
First get the demo app working.
This ensures you have your app ID and worked out how to add the URL stuff into the plist. This is explained in the docs so should not give you much trouble.
Once all the options in the demo app work (login, post, upload a sample photo) you can think about your own app.
Many things are different but you still need to have the AppDelegate method for the URL stuff. Also this method does not work as is assuming your app is using more than one view controller.
I went for the approach of setting up facebook in the app delegate eg:
Facebook *facebook
and in the actual facebook routine referencing that appDelegate's facebook object eg:
appDelegate.facebook
This approach is the subject of quite a few posts on the interweb so you should be able to google it.
I can log on, get info, post & upload photos.
I'm having the same issue, i downloaded the "official example" from gitHub, and wehn compiled it does she#. After i login, it open safari and redirects to http://www.facebook.com/connect/uiserver.php, and the app stalls. Well that's not the way to do it, Facebook. They are obsoleting the old rest api, meanwhile the "new" graph things not working. Im currently using graph API with my own calls to graph.
Check if you have done the following
1.URL scheme corresponding to your Facebook application ID is set. Your URL Schemes must contain item looking like "fb1234567890"
2.AppDelegate's method must be implemented:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
it is described in https://github.com/facebook/facebook-ios-sdk "Authentication and Authorization".
Read also "Single Sign-On".

Resources