Objective c 如何在fb上共享我的应用程序url?
这是我重定向到facebook的代码-Objective c 如何在fb上共享我的应用程序url?,objective-c,Objective C,这是我重定向到facebook的代码- (void)fb_BtnPressed:(UIButton*)button { [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://www.facebook.com/"]]; } 为此,您应该使用iOS中提供的社交框架,您可以找到更多关于它的信息 if ([SLComposeViewController isAvailableForServiceTy
(void)fb_BtnPressed:(UIButton*)button
{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://www.facebook.com/"]];
}
为此,您应该使用iOS中提供的社交框架,您可以找到更多关于它的信息
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[vc setInitialText:@"Your URL"];
[self presentViewController:vc animated:YES completion:nil];
}
或者你可以使用深度链接 下面是一个博客,它将引导你了解什么是深度链接,以及如何在我们的应用程序中实现它 在appdelegate.m中,添加此方法
-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)url源应用程序:(NSString*)源应用程序注释:(id)注释
{
NSString*路径=[url路径];
NSString*query=[url查询];
if([查询IsequalString:@“1”])
{
vc=[story InstanceEviewControllerWithiIdentifier:@“主页”];
vc1=[story InstanceEviewController标识符:@“firstStoryboard”];
self.navController=[[UINavigationController alloc]initWithRootViewController:vc];
[self.navController pushViewController:vc1动画:否];
self.window.rootViewController=self.navController;
}
返回YES;
}
我在我的一个应用程序中这样做了。使用下面提到的代码:
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//to add a link to your fb post which will display as per the metadata of your url
[mySLComposerSheet addURL:[NSURL URLWithString:@"http://www.sampleurl.com"]];
//this will just display a plain text of fb post
[mySLComposerSheet setInitialText:@"http://www.sampleurl.com"];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
希望这有帮助。首先添加Social.framework 然后将#导入添加到您的文件中 并添加以下代码以打开SLComposeViewController:
SLComposeViewController *mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:@"<YOUR APP URL>"];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
NSLog(@"Successfully shared on your wall");
break;
default:
break;
}
}];