Facebook 应用程序邀请通知在 ios 中不起作用 [英] Facebook App invites notification not working in ios

查看:22
本文介绍了Facebook 应用程序邀请通知在 ios 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在演示应用程序中实现了 Facebook 应用程序邀请.它运行良好,但没有收到通知.

<块引用>

我已经在我的问题中添加了所有细节,现在谁能告诉我什么是我的代码中的问题以及我应该怎么做才能解决这个问题.我有创建了用于测试此应用的测试用户.

此代码工作正常,它会启动一个对话框,显示好友列表并显示已发送应用邀请,但当我在好友帐户中查看时,它没有显示任何通知.

<块引用><块引用>

我的 Info.plist 文件

我想我在 URL Type (URL方案).我写了 action 是方法的名字,但我没有知道我应该在这个专栏写什么.

<块引用>

Appdelegate.m

- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication注释:(id)注释{BFURL *parsedUrl = [BFURL URLWithInboundURL:url sourceApplication:sourceApplication];if ([parsedUrl appLinkData]){NSURL *targetUrl = [parsedUrl targetURL];[[[UIAlertView alloc] initWithTitle:@"收到的链接:"消息:[targetUrl absoluteString]代表:无取消按钮标题:@"好的"otherButtonTitles:nil] 显示];}返回是;}

<块引用>

视图控制器.h

appInviteDialog:(FBSDKAppInviteDialog*)appInviteDialog didCompleteWithResults:(NSDictionary *)results 调用

- (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(@" 结果 %@",results);}- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error{NSLog(@"error = %@", 错误);NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:@"发送邀请时出现问题,请稍后再试.";NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops!";[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];}

解决方案

尝试在你的 AppDelegate.m 中加入这个:

在顶部导入:

#import 

并将其用于应用程序:openurl: sourceapplication: annotation

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation{如果(!网址){返回否;}[[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];返回是;}

这使用 Facebook SDK 来处理 openurl,而不是自定义处理程序.

这将触发您定义的委托方法,然后您可以继续提醒用户或做任何您想做的事情.

同样在您的 info.plist 中,URLSchemes 值需要与您在 Facebook 输入具有自定义方案的 URL"中的值相同.例如,如果您在 Facebook 对话框的带有自定义方案的 URL"中有 myapp://,那么您的 URLScheme 将是 myapp (你目前有action)

所做的只是让 Safari 知道如果您在 URL 栏中调用 myapp:// 那么它应该打开您的应用程序.除非您向应用传递参数,否则 Facebook 屏幕中 myapp:// 之后不需要任何内容​​.

确保在您的开发者设置中(

您可以为 iPhone 使用任何应用程序 ID(来自 iTunes Connect 的应用程序 ID,实际上称为Apple ID").iPad 应用 ID(只需确保它是来自应用商店的有效 ID,名称不必匹配)并为您的应用使用捆绑 ID.iPhone & 的编号iPad ID可以相同.这很重要,因为如果没有这个,Facebook 不会向用户发送通知,因为如果用户没有下载应用程序,它不知道将用户发送到哪里.将其放入并发送另一个通知,它应该可以工作.

使用 Facebook 的快速入门"创建应用邀请链接时,请确保您在 iOS 框中正确设置了参数.这是设置应该是什么样子的示例.这是看起来像 https://fb.me/6344111666661512

的链接

具有自定义方案的 URL"必须与 info.plist 中的任何内容相同 - 如果您的 myapp 中有 myapp,请使用上面的答案code>info.plist 在 URLSchemes 下,您可以将myapp://"放在 Facebook具有自定义方案的 URL"中.应用程序名称可以是任何内容,仅用于显示.虽然它说App Store Id"是可选的,但它是必需的.确保在此处使用与上面设置iPad 商店 ID"和iPhone 商店 ID"相同的方法.这会告诉 Apple,如果用户没有您的应用,就将其推送到 iTunes 商店.

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.

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];

}

解决方案

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.

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

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.

这篇关于Facebook 应用程序邀请通知在 ios 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆