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

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

问题描述

我已经在Demo应用程序中实施了Facebook App邀请。它的工作正常,但没有得到通知。


我已经添加了我的问题的所有细节,现在有人可以告诉我什么是
我的代码中的问题,我应该怎么做来解决这个问题。我有
创建测试用户来测试这个程序。


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



我的Info.plist文件


我想我有一个错误在info.plsit的URL类型(URL
方案)下。我已经写了这个方法的名字,但是我没有
有什么想法应该写在这一列。



Appdelegate.m




   - (BOOL)应用程序:(UIApplication *)应用程序
openURL:(NSURL *)url sourceApplication :(NSString *)sourceApplication
注释:(id)注释{
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



appInviteDialog:(FBSDKAppInviteDialog
*)的AppInviteDialog didCompleteWithResults:(NSDictionary *)结果
调用




   - (IBAction)操作:(UIButton *)发件人
{

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

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

- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)结果
{
NSLog(@result%@,results );
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError :( NSError *)错误
{
NSLog(@error =%@,error);
NSString * message = error.userInfo [FBSDKErrorLocalizedDescriptionKey]?:
@发送邀请时发生问题,请稍后重试。
NSString * title = error.userInfo [FBSDKErrorLocalizedTitleKey]?:@Oops!;

[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@OKotherButtonTitles:nil] show];

}


解决方案

这在您的AppDelegate.m



导入此顶部:

  #import< FBSDKCoreKit / FBSDKCoreKit.h> 

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


$ (UIApplication *)应用程序openURL(NSURL *)url sourceApplication:(NSString *)sourceApplication注释:(id)注释
{
if(!url){
return NO;
}

[[FBSDKApplicationDelegate sharedInstance]应用程序:application openURL:url sourceApplication:sourceApplication annotation:annotation];

返回YES;
}

这使用Facebook sdk处理openurls而不是自定义处理程序。 p>

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



另外在你的info.plist中,URLSchemes的值需要和你在facebook中输入使用自定义方案的url一样。例如,如果您在Facebook对话框上的url with a custom scheme中有 myapp:// ,那么您的URLScheme将为 myapp (你当前有动作



所有这一切都是让Safari Safari知道如果你打电话'url吧'中的'myapp://'然后应该打开你的应用程序。除非你传递参数到应用程序,否则在Facebook屏幕上的'myapp://'之后不需要任何东西。



/ -----侧面注----- /



确保在您的开发人员设置(



您可以使用任何应用程序ID(来自itunes连接的一个,实际上称为apple id)用于iphone& ipad应用程序ID(只需确保其从应用程序商店有效的名称,名称不必匹配),并使用您的应用程序的包ID。 iPhone& ipad id 可以相同。这是至关重要的,因为Facebook没有通知用户没有这个,因为它不知道在哪里发送用户,如果他们没有下载的应用程序。把它放在并发送另一个通知,它应该工作。



/ ----------侧注2 --------- ---- /



使用Facebook的快速入门创建应用邀请链接时,请确保您正确地在ios框中设置参数。这是一个示例,该设置应该是什么样的(这是一个链接,看起来像 https://fb.me/ 634411166661512



< img src =https://i.stack.imgur.com/yTzX3.pngalt =fb应用程序链接的示例设置>



在您的info.plist中,Url与自定义方案需要相同,如果您在info.plist的URLSchemes中有myapp,则可以使用上面的答案将myapp://放在FacebookUrl with a custom scheme。应用程序名称可以是任何东西,仅供显示。虽然说App Store Id是可选的,但它是必需的。确保您在这里使用与上述设置iPad Store Id和iPhone Store Id相同的内容。如果没有您的应用程序,则会告诉苹果将用户推送到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 dont need anything after the 'myapp://' in the facebook screen.

/-----SIDE NOTE-----/

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 dont 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 doesnt deliver the notification to the user without this because it doesnt know where to send the user if they havent downloaded the app. Put this in and send another notification and it should work.

/----------SIDE NOTE 2-------------/

When using facebooks 'Quick Starts' to create the app invite link, make sure you are setting up the parameteres 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, thats 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天全站免登陆