Facebook App invites notification not working in ios
Asked Answered
P

4

8

I had implemented Facebook App invites in Demo Application. It worked fine but did not get notification.

I have added all detail in my question, now can anyone tell me what is the issue in my code and what should I do to resolve this. I have created test users for testing this app.

This code works fine, it launches a dialogue box, showing the friend list and also shows that the app invite is sent but when I check it in friends account it doesn't show any notification.

My Info.plist File

I think I have a mistake in info.plsit under URL Type (URL Schemes). I had written action which is the name of the method but I don't have any idea what I should write in this column.

enter image description here

Appdelegate.m

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url   sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    BFURL *parsedUrl = [BFURL URLWithInboundURL:url sourceApplication:sourceApplication];
    if ([parsedUrl appLinkData])
    {
        NSURL *targetUrl = [parsedUrl targetURL];
        [[[UIAlertView alloc] initWithTitle:@"Received link:"
                                    message:[targetUrl absoluteString]
                                   delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
    }
        return YES; }

ViewController.h

Getting result null when appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results called

- (IBAction)action:(UIButton *)sender
{

    FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
    content.appLinkURL = [NSURL URLWithString:@"https://fb.me/*****************"];

    [FBSDKAppInviteDialog showFromViewController:self withContent:content delegate:self];
}

 - (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@" result %@",results);
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
    NSLog(@"error =  %@", error);
    NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:
    @"There was a problem sending the invite, please try again later.";
    NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops!";

    [[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

}
Paedo answered 19/11, 2015 at 11:35 Comment(1)
Hey i am also facing same issue. did you find proper solution?Mccurry
H
15

Try having this in your AppDelegate.m:

Import this at the top:

#import <FBSDKCoreKit/FBSDKCoreKit.h>

And use this for the application: openurl: sourceapplication: annotation

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    if (!url) {
        return NO;
    }

    [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];

    return YES;
}

This uses the Facebook SDK to handle openurls instead of a custom handler.

This will trigger the delegate methods you have defined and then you can proceed to alert the user or do whatever you want.

Also in your info.plist the URLSchemes value needs to be the same as what you have in your Facebook input 'URL with a custom scheme'. For example if you have myapp:// in your 'URL with a custom scheme' on the Facebook dialogue then your URLScheme would be myapp (where you currently have action)

All that does is lets Safari know that if you call myapp:// in the URL bar then it should open your app. Unless your passing parameters to the app you don't need anything after the myapp:// in the Facebook screen.

Make sure in your developer settings (https://developers.facebook.com/apps/{app-id}/settings/) you have added the platform iOS, and have set up both a bundle id and the iPhone store id and iPad store id.

Screenshot from my app on Facebook developer page

You can use any app id (the one from itunes connect, actually called 'Apple id') for the iPhone & iPad app id (just make sure its a valid one from the app store, names don't have to match) and use your bundle id for your app. The number for the iPhone & iPad id can be the same. This is crucial as Facebook doesn't deliver the notification to the user without this because it doesn't know where to send the user if they haven't downloaded the app. Put this in and send another notification and it should work.

When using Facebook's 'Quick Starts' to create the app invite link, make sure you are setting up the parameters in the iOS box correctly. Here is an example of what the setup should look like. This is the link that looks like https://fb.me/634411166661512

Example setup of fb app link

The "URL with a custom scheme" needs to be the same whatever you have in your info.plist - using the answer above if you have myapp in your info.plist under URLSchemes you would put "myapp://" in the Facebook "URL with a custom scheme". The app name can be anything, that's just for display. Although it says "App Store Id" is optional, it is required. Make sure you use the same one in here as you did above where you set your "iPad Store Id" and "iPhone Store Id". This tells Apple to push the user to the itunes store if they do not have your app.

Houlihan answered 19/11, 2015 at 15:44 Comment(7)
Hey... Thanks for you help... Now its returning me ******result { didComplete = 1;***** when ****didCompleteWithResults**** is called.. But still No notification received to another device.Paedo
I had created 2 test user and both are friends of each other, I had installed app in one device and logged in with one test_user1, and I had logged in by test_user2 in another device and not installed the application in that device. Now I am sending notification from test_user1 to test_user 2, but there is no notification received by test_user2Paedo
Updated my answer to explain this. See 'Side Note'Houlihan
Hey thanks for your answer.. It works. But still there is an issue... When I am sending notification from test_user1 to test_user2 it receives the notification, but not showing in notification in notification view of iPhone. It directly showing at Facebook app icon.Paedo
Updated my answer.... again :). I tried your app link that you are sending, and it takes me to the facebook apps page, and says parameters missing. This makes me think that something is wrong in your link configuration. To create a new link, go to link and create a new link but make sure you look at my answer and confirm that you have all of the needed info inputted in the right spot.Houlihan
Hey.... thank you so much for your help... but According to your answer I have to enter only App Store ID , and I had entered it, but still not working....Paedo
May be I had added all credential wrong that's why its happening... But When I am gonna to implement it in live application i will add all credential right and may it works then...Paedo
M
3

Go to developer dashboard. select your app. add platform "Facebook canvas", set canvas url. Hope it works

Mcwherter answered 5/4, 2016 at 6:55 Comment(0)
F
0

To get working notifications, go to the settings and add the required platforms. If you want to get notification on iOS native app than add "iOS" platform same for "Android" and for web add "Facebook Canvas". Add the required data for each platform and than try. Hope it will work.

Remember: For iOS and Android native apps, you must have to add the data of the live apps :)

Fluorescent answered 11/5, 2016 at 9:4 Comment(0)
M
0

App Invites is only working on Mobile Platform. I was also facing same issue i was testing on Simulator to Web. Hope this will helps :)

enter image description here

Mccurry answered 28/12, 2016 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.