ios fetch defer deeplink always null objective c by using facebook sdk - objective-c

I am using facebook SDK , and when I am trying to invite friend via facbook by using fb invite deep linking.
NSDictionary * getParam = #{
#"access_token":accessToken,
#"fields":#"canonical_url",
#"pretty":#(YES),
};
NSString * getCanoicalURL = [NSString stringWithFormat:#"%#/%#",FB_CANONICAL_API, fbAPILinkID];
[self GET:getCanoicalURL parameters:getParam success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject)
{
NSError *error;
FacebookLink * getResult = [MTLJSONAdapter modelOfClass:[FacebookLink class] fromJSONDictionary:responseObject error:&error];
if (error)
{
handler(nil,error);
}
else
{
handler(getResult.canonicalUrl,nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
{
handler(nil,error);
}];
The below is my invite friend method it show successfully :
-(void)inviteFriend:(NSString*)canonicalUrl
{
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL =[NSURL URLWithString:canonicalUrl];
[FBSDKAppInviteDialog showFromViewController:self withContent:content delegate:self];
}
But when I try to fetch for defer deep link it always null:
FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error)
{
NSLog(#"fetch defer app link :%#",url);
if (error) {
NSLog(#"Received error while fetching deferred app link %#", error);
}
if (url) {
[[UIApplication sharedApplication] openURL:url];
}
}];

Be sure that your iPhone's Limit Ad Tracking setting is off, at Settings -> Privacy -> Advertising

Get parts of a NSURL in objective-c
This will be ur exact reference and answer not so manual coding as above.

Related

Fabric showWithCompletion after login

I can login with "[[Twitter sharedInstance] logInWithCompletion..."
I can showWithCompletion too.
But,I can't TWTRComposer showWithCompletion after login completion.
not Crash, but Composer dialog not show.And show error
This is my Code
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
//
TWTRComposer *composer = [[TWTRComposer alloc] init];
NSString* composerText = #"Text";
[composer setText:composerText];
[composer setImage:[UIImage imageNamed:#"image.png"]];
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
//
if (result == TWTRComposerResultDone) {
NSLog(#"Post Tweet successfully");
}
else {
NSLog(#"Unable to post Tweet");
}
}];
}];
Error:
CoreText performance note: Client called CTFontCreateWithName() using name "STHeitiTC-Medium" and got font with PostScript name "PingFangTC-Medium". For best performance, only use PostScript names when calling this API.
Thx~

CKDiscoverAllContactsOperation not fetching contacts

I am using CKDiscoverAllContactsOperation but its not working fine for me.
-(void)queryForAllUsers: (void (^)(NSArray *records))completionHandler {
CKDiscoverAllContactsOperation *op = [[CKDiscoverAllContactsOperation alloc] init];
[op setUsesBackgroundSession:YES];
op.queuePriority = NSOperationQueuePriorityNormal;
[op setDiscoverAllContactsCompletionBlock:^(NSArray *userInfos, NSError *error) {
if (error) {
NSLog(#"An error occured in %#: %#", NSStringFromSelector(_cmd), error);
//abort();
} else {
NSLog(#"Number of records in userInfos is: %ld", (unsigned long)[userInfos count]);
dispatch_async(dispatch_get_main_queue(), ^(void){
completionHandler(userInfos);
});
}
}];
[self.container addOperation:op];
}
The container which I'm using is publicCloudDatabase.
The search only works if different users activate the app, approved to be Discoverable and have the other person's iCloud email address in their Contacts.
You should use the discoverAllContactUserInfosWithCompletionHandler on the container like this:
[self.container discoverAllContactUserInfosWithCompletionHandler:^(NSArray *userInfos, NSError *error) {
..
}
this function will only return the contacts that can be linked to an iCloud account and the person has also started up your app.

Sharing my ios app details on facebook along with a facebook share

I am adding share functionalities on my facebook app.Like When a "saying" is selected there is a button for sharing that "saying" on facebook.And while clicking this button I can only see the shared saying on my facebook page,there isnt any information about my ios app.How can I make everyone knows that this saying is shared through my iOS app? Please help me....
I may be a little late. Hope this helps.
You have to use the Accounts framework and the Social framework to share with your app name.
First make sure you have set up your App on Facebook correctly. Then you can use the Facebook App ID to share your posts through your app.
Here is a sample code that shows you how to use the Accounts framework with the Social Framework :
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = #[#"email"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"275485699289493", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
/**
* The user granted us the basic read permission.
* Now we can ask for more permissions
**/
NSArray *readPermissions = #[ #"publish_actions"];
[dict setObject:readPermissions forKey: ACFacebookPermissionsKey];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if(granted && error == nil) {
NSDictionary *parameters = #{#"message": #"This Should Work Perfectly !! "};
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
feedRequest.account = self.facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
// Handle response
}];
} else {
NSLog(#"error is: %#",[error description]);
}
}];
} else {
NSLog(#"error is: %#",[error description]);
}
}];
}

openActiveSessionWithReadPermissions does not log in automatically

I have recently started using Facebook SDK 3.1, and am encountering some problems with logging in using openActiveSessionWithReadPermissions.
Actually, loggin in works perfectly, if there is a cached token available, it logs in without presenting Facebook UI, and if not, it presents the UI.
The problem occurs after I make a call to reauthorizeWithPublishPermissions. If I call reauthorizeWithPublishPermissions, then close and reopen the application, and make a call to openActiveSessionWithReadPermissions, it presents the Facebook UI and requires the user to say "yes I'm OK with read permissions", even though there is a cached token available.
It only presents the Facebook UI erroneously if I make a call to reauthorizeWithPublishPermissions, otherwise everything works fine.
Open for read code:
[FBSession openActiveSessionWithReadPermissions:readpermissions allowLoginUI:YES
completionHandler:^(FBSession *aSession, FBSessionState status, NSError *error) {
[self sessionStateChanged:[FBSession activeSession] state:status error:error];
if (status != FBSessionStateOpenTokenExtended) {
// and here we make sure to update our UX according to the new session state
FBRequest *me = [[FBRequest alloc] initWithSession:aSession
graphPath:#"me"];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *aUser,
NSError *error) {
self.user = aUser;
aCompletionBlock(aSession, status, error);
}];
}
}];
the sessionStateChanged function:
- (void)sessionStateChanged:(FBSession *)aSession state:(FBSessionState)state error:(NSError *)error {
if (aSession.isOpen) {
// Initiate a Facebook instance and properties
if (nil == self.facebook || state == FBSessionStateOpenTokenExtended) {
self.facebook = [[Facebook alloc]
initWithAppId:FBSession.activeSession.appID
andDelegate:nil];
// Store the Facebook session information
self.facebook.accessToken = FBSession.activeSession.accessToken;
self.facebook.expirationDate = FBSession.activeSession.expirationDate;
}
} else {
// Clear out the Facebook instance
if (state == FBSessionStateClosedLoginFailed) {
[FBSession.activeSession closeAndClearTokenInformation];
}
self.facebook = nil;
}
}
the Publish call, with an empty aPublishAction for testing:
- (void)doPublishAction:(void(^)(FBSession *aSession, NSError *error))aPublishAction {
if ([FBSession.activeSession.permissions
indexOfObject:#"publish_actions"] == NSNotFound) {
NSArray *writepermissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
#"publish_actions",
nil];
[[FBSession activeSession]reauthorizeWithPublishPermissions:writepermissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *aSession, NSError *error){
if (error) {
NSLog(#"Error on public permissions: %#", error);
}
else {
aPublishAction(aSession, error);
}
}];
}
else {
// If permissions present, publish the story
aPublishAction(FBSession.activeSession, nil);
}
}
Thanks for everything in advance, I would be grateful for any and all help!!
You need to add
[FBSession.activeSession handleDidBecomeActive];
to your -(void) applicationDidBecomeActive:(UIApplication *)application method in your app's delegate as stated in the migration guide.
What if you use openActiveSessionWithPermissions instead of openActiveSessionWithReadPermissions?

How to comment on a post in facebook3.1 using graph api in ios

I use Facebook 3.1 and try comment on a particular post. I have used the following code. I have used the below mentioned permissions also while creating session:
read_stream,offline_access,publish_stream,share_item
The code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"This is my comment", #"message", nil];
NSString *string=[NSString stringWithFormat:#"https://graph.facebook.com/153125724720582_184234384932460/comments?access_token=%#",appDelegate.session.accessToken];
[FBRequestConnection startWithGraphPath:string
parameters:params
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
}];
Response :
Result: {
comments = 1;
id = "https://graph.facebook.com/153125724720582_184234384932460/comments";
}
But my message is not updated on commented post id.
Same code with Post request also I have tried but Response is:
Result: {
"FACEBOOK_NON_JSON_RESULT" = false;
}
You should use an HTTP POST and make sure that the user has granted publish_stream permissions.
You should copy and paste the API call (and the access token) into the Graph Explorer to test your call out.
(Also use the access_token debugger to make sure the permission is there)
You should use this
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Test Comment", #"message", nil];
[FBRequestConnection startWithGraphPath:#"153125724720582_184234384932460/comments"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
NSLog(#"Error: %#", [error localizedDescription]);
else
NSLog(#"Result: %#", result);
}];