Facebook send message through iOS - ios

I am using this code to send a message:
//send message
NSString *friendList = #"1372394537";
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Check this out.", #"message",
friendList, #"suggestions",
nil];
[self.facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
//send message
My app logs in with facebook, shows a friend list, and then adds the Friend's ID's in the friendList, but they receive no message!! Why??

What you are sending is a request and not a message. There is a big difference.
The message you are talking about is simply a parameter that you can pass along with the request.
The most frequent problem that I see people dealing with when requests do not arrive is that the application is set to sandbox mode. If the application is in sandbox mode, only users listed in the "roles" section within your application will be able to receive the requests (admins, developers, testers...).
One other thing that could be at work here is that the canvas URL is not set for your application. When users act on requests they are sent to the application's canvas URL. When you don't set that value there is no place for the request to send the user so the request is nullified and doesn't reach the user.
So two things for you to try -
Remove your application from sandbox mode.
Make sure that you have set the canvas URL property for your application.

Related

SKReceiptRefreshRequest not working the second time it is called after a cancel

My app starts and checks for the receipt. Because it is sandbox, the first time the app runs from Xcode, it needs to ask the App Store for the receipt. So I use SKReceiptRefreshRequest to request it.
A window pops up, asking for the App Store credentials. If I type the credentials, then the app loads the receipt, I validate it, and the app runs fine.
The problem starts if I cancel that credential window.
Then I have the first problem. At this time the app has no receipt, so I cannot validate to see if the copy is pirate. What to do? I tried the following approach: instead of disabling the application, when the user tries to use the app, I show a window saying "could not validate the application, type OK to validate now".
When the user types OK, I trigger SKReceiptRefreshRequest a second time. Again a credential window pops up, I type the valid credentials and nothing happens. After 2 or 3 minutes of nothingness, a windows pops up saying "cannot connect to App Store".
The strange part is that none request:didFailWithError: or requestDidFinish: methods of SKReceiptRefreshRequest delegate are called during this failure. Receipt retrieval fails without triggering any delegate method and yes, the delegate is assigned.
The code for the receipt retrieval is the traditional one, that is
SKReceiptRefreshRequest *refreshReceiptRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
refreshReceiptRequest.delegate = self;
[refreshReceiptRequest start];
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
NSLog(#"ERROR");
}
- (void)requestDidFinish:(SKRequest *)request {
if([request isKindOfClass:[SKReceiptRefreshRequest class]])
{
NSLog(#"App Receipt exists after refresh");
} else {
NSLog(#"Receipt request done but there is no receipt");
}
}
Apparently this is a bug of SKReceiptRefreshRequest. If the user cancels the first credential box, the application will not able to retrieve the receipt a second time, at least not in sandbox mode. Because this will not work on sandbox mode, you cannot test and this will also not work when Apple review your app and your app will be rejected.
Also, killing the app from the task bar will not help to make the credential box appear a second time.
The only solution is to present an alert, telling the user to remove and download your app again from the store and to not cancel the credential box when the app asks for the apple ID/password.

Facebook iOS SDK 3.1: "Error: HTTP status code: 400"

I am running the Facebook SDK 3.1 on Xcode 4.5GM with iOS6 simulator. I connect to FB in the iOS settings and successfully FB connect in my app using the new iOS6 FBConnect UI. I have an access token, can see my friends, send app requests, post to my wall, etc. However, every time I initiate any sort of FBURLConnection is made, I see this printed to my console:
Error: HTTP status code: 400
I went into the FB code and printed the reponse when this error is printed and I get:
{
body = {
error = {
code = 100;
message = "(#100) The parameter 'attribution' is required for the 'mobile_app_install' activity";
type = OAuthException;
};
};
code = 400;
}
Does anyone know how to resolve this? All functionality seems to work, but I keep seeing this spam my console.
Right after the session is created do this:
[FBSession setActiveSession:session];
As best as I can tell, this is a bug introduced in the 3.1 SDK. Looking at the network traffic with Charles, they’re trying to POST to graph.facebook.com/[user id]/activities but it’s failing.
After much troubleshooting and looking at all the suggestions on Stackoverflow, I got this error 400 (error.code = 5) thing resolved.
The solution in my case was to make sure the params (aka postParams) included in my startWithGraphPath call had exactly the params supported by the type of content being posted.
More specifically, I was posting a link to me/feed with the #"ref" key (typically used for tracking with FB Insights).
After removing the #"ref" key, startWithGraphPath succeeded.
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test NAME field (from ios app)", #"name",
#"Test caption", #"caption",
#"Test description", #"description",
#"http://example.com/test1.html", #"link",
#"http://example.com/water.jpg", #"picture",
// #"foo", #"ref", // WRONG!
nil];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
My activeSession (and all other possible culprits) checked-out OK.
This is the same as my answer from here: Facebook SDK 3.1 - Error: HTTP status code: 400
But it could help people still getting the 400 error.
The original issue was resolved by Facebook just after the 3.1 SDK was released.
But some are still having issues, if you have this issue you should check the login flow, and look at facebooks examples, if you are still having issues this could be a hint to a solution.
I got the 400 error when I do not have authorization to get to my information. The strange thing is that I get an accessToken and even a valid login (this is because I structured my code, with the help according to Scrumptious example and I did a valid login when the Session state is open).
The FBSessionState is only opened for like a second and then it changes to closed with an 400 Error.
With iOS6 native login you get the permission alert when you ask for it, and then the phone remember that choice for 24 hours. But if the user logs in to the facebook home-page and then deletes permission for the application the phone will remember that setting for 24 hours, regardless if you re-install the app or not.
This I found out after some hours of debugging, since I allowed the application from the Settings in iOS, but I could not post, and since I deleted the permission from the facebook privacy, and the alert would not show again there was nothing I could do but to manually give me permissions via a debug tool or wait 24 hours so I could accept the facebook-permission alert again.
I discovered that Status Code 400 is also thrown with FBErrorHTTPError when something go wrong with Optional Properties in Define Action Type fieldset, within the Facebook=>Open Graph definition panel.
In my case I was posting an action object without a property marked as isRequired. Be also aware for isArray option and in general, for right matching with what you're sending.
This error reflected a bug on the server, which was fixed shortly after the 3.1 release was published. At this point there should be no more failures coming from this request. Hope this helps!

Check success of facebook dialog post in Facebook iOS SDK

Is there a way to check if a post sent via dialog:
[facebook dialog:#"feed"
andParams:params
andDelegate:self];
was sent successfully or not? I've looked through the Facebook iOS SDK and cannot find a delegate method for it. There is dialogDidComplete but this doesn't give me information on the success of the post.
It is better to use dialogCompleteWithUrl to ensure that content was posted, as dialogDidComplete will not provide those details.
This is outlined in Sample Application (Hackbook) dialogCompleteWithUrl (see Line 1182 for exact usage of post_id field).
Look into the source code of the Facebook finish and you will also see this:
[[NSNotificationCenter defaultCenter] postNotificationNamed:#"facebookWallPosted"...
Or similar. Just intercept that notification and do what you need to. Even the failures post the same notification name

Facebook IOS SDK: Error in Publish Story Dialog

I've successfully set up the "DemoApp" project from the Facebook IOS SDK to use my "OKC ThunderCast" Facebook application. I have also configured another "Tester" application from scratch to successfully use the Facebook SDK and publish stories to my news feed. However, in my production application, I always get this result when calling the "dialog" method. The full description of the error message is "Error on line 52 at column 17: Opening and ending tag mismatch: div line 0 and body"
Here's a detailed walkthrough of all of my code to make sure nothing is missed.
1) A UIViewController calls the "authorize" method
NSArray *fbPerms = [NSArray arrayWithObjects:#"read_stream", #"offline_access", nil];
[[FacebookSingleton sharedInstance].facebook authorize:fbPerms delegate:self];
Note: The FacebookSingleton is a class I wrote that always returns a single instance of the "Facebook" class. I am using it successfully in other applications.
2) Safari is opened and the user is successfully authenticated and authorized
3) The application is called back and the "handleOpenUrl" method is called, which calls the "fbDidLogin" method of the UIViewController
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
Facebook *fb = [FacebookSingleton sharedInstance].facebook;
return [fb handleOpenURL:url];
}
4) The same UIViewController handles the "fbDidLogin" event, and calls the "dialog" method
- (void)fbDidLogin
{
[[FacebookSingleton sharedInstance].facebook dialog:#"feed" andDelegate:self];
}
I also have the necessary "URL Schemes" and "URL Types" entries in the .plist file. To my eyes, I am using exactly the same code in the "DemoApp", "Tester", and production applications. But while the DemoApp and Tester work, I always see this HTML error in the feed dialog in my production application. Has anyone seen a similar issue? Could it be related to the Facebook "Bundle ID" setting in the Facebook application settings? Is there some build or .plist setting that is different?
I have invested a great deal of time into troubleshooting with no success in several weeks. Thanks in advance...
The cause of the problem was setting a value to the key "User-Agent" in the NSUserDefaults dictionary. I wanted to specify my own User-Agent to uniquely identify my iOS app. But somehow setting this value caused the problem above. When I simply renamed this key to "OKCTC-User-Agent" the error was immediately resolved.
I did log an issue on the GitHub site for the Facebook-IOS-SDK. Hopefully this will help others who have encountered similar problems.

iphone 4.0 sending sms programmatically

I am working on a simple application in which I need send sms programmatically to my friends.
so write below code for sending sms .
MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init]autorelease];
if([MFMessageComposeViewController canSendText])
{
picker.messageComposeDelegate = self;
picker.recipients =[NSArray arrayWithObject:#"123"];
picker.body=#"hello";
[self presentModalViewController:picker animated:YES];
}
but I do not want to load message picker and send sms to friends.
// [self presentModalViewController:picker animated:YES];
is it possible to send sms without click in send button.
The two options available in the iOS API are:
MFMessageComposeViewController - requires user confirmation
sms:// URLs - requires user confirmation
If you want to do something else, you'll need to set up a network-based service with an SMS gateway provider and send messages via that. I used to work with such a provider that had an HTTP POST interface, which would be simple enough to use. That comes with a couple of important differences:
the SMS is actually sent by the gateway server, not the handset (though you can usually rewrite the sender ID and get the message billed to the handset owner)
you'll need to pay for access to the service, which might include paying per message (or more likely per 1,000 messages)
Also note that sending SMS on your users' behalf without confirmation might be frowned upon when your app is reviewed, especially if they're billed for.

Resources