ShareKit for iphone - SHKShareTypeText - iphone

I am using ShareKit for iphone to share some text in facebook. Can any one tell me which delegate is called after publishing the text successfully. I need this to inform the user that his action was successful.

The shareDelegate property in SHKSharer isn't the easiest to get to and change, but there are notifications sent from the delegate methods of SHKSharer, one for each of the methods: SHKSendDidStartNotification, SHKSendDidFinish, SHKSendDidCancel, SHKSendDidFailWithError. Observing these notifications turns out to be a simple way of listening for the outcome of sharing.

See shareDelegate property of SHKSharer . All the concrete sharers (e.g. SHKFacebook) extend this base class.
Having said that, I'm not sure where you set a class to be the delegate using ShareKit's public API (so I'm not claiming this to be a complete answer).

Related

How to use standard events in the react native Facebook SDK

The Facebook SDK has the ability to record both custom events and standard events. The standard events are things like "Purchases" "Add to cart" "Completed Registration" etc...
Recording these standard events gives you access to specific bidding features on Facebook ads that you don't get without the events.
I have an app that has the React Native FBSDK
There are two methods for defining an event - one for purchases and one for everything else as seen here
There is zero documentation for standard events on react within the SDK on Github or on the event tracking docs on Facebook's developer platform.
Right now I'm trying to track the standard events by using their various names, as recorded across FB's documentation. I've tried the following:
AppEventsLogger.logEvent('FBSDKAppEventNameCompletedRegistration');
AppEventsLogger.logEvent('CompletedRegistration');
AppEventsLogger.logEvent('Completed Registration');
All of these just create custom events with those names, but aren't recognized as standard events.
Has anyone gotten standard events to work using the React Native wrapper for the FB SDK? If so how do you name the events to get FB to recognize them?
Update: As the comment below highlights, the more recent link is https://developers.facebook.com/docs/marketing-api/app-event-api/
It looks like you'll have to pass the strings that those standard events get evaluated to, i.e. instead of 'FBSDKAppEventNameCompletedRegistration', you'll have to use: 'fb_mobile_complete_registration'.
Here's the source:
Sorry if this is a bit late. Hope this helps.
I managed to find the actual event name by generating standard event code using tool on Facebook's documentation, run the code in AppDelegate.m, and get the exact key-values from Events Manager. With this roundabout way, I realized the actual name of Add to Cart event was fb_mobile_add_to_cart. From there I googled for the name and found the list documented in Marketing API (why not App Events?).
I don't know if it is the right place, but you can refer to https://developers.facebook.com/docs/marketing-api/app-event-api/ for actual standard event names and parameter names. At least it worked in my case. Here's my Add to Cart event code:
function logAddToCart(totalPrice, contentType, contentId, currency) {
const params = {
'fb_content_type': contentType,
'fb_content_id': contentId,
'fb_currency': currency
};
AppEventsLogger.logEvent('fb_mobile_add_to_cart', totalPrice, params);
}
I made a simple package with all events. Just import like
import FBEvents from "react-native-fbsdk-events";
// ...
AppEventsLogger(FBEvents.COMPLETE_REGISTRATITON, params);

Cocoa Design Patterns for Authentication

After developing for iOS for some time now, I have gotten comfortable with the language and am trying to get better at designing well-structured applications. Initially my focus was on seeing something functional, so I ended up with gigantic view controllers which were horribly architected. Now, I'm learning to separate my model classes and trying to keep my architecture more modular. I would greatly appreciate any advice on the following sample situation:
I am developing an app which (among other things) pulls a list of articles from a server and displays them. However, the user has to be authenticated to be able to retrieve this list. Because other aspects of the application utilize the same authentication, I want a single class to manage the authentication. The goal is that when any controller requests data from the model which requires authentication, if the user is not authenticated, the authentication prompt will automatically be presented.
I expect to create the following:
VIEW
- ArticlesView
- AuthenticationView
CONTROLLER
- ArticlesViewController
- AuthenticationViewController
- ArticleManager (singleton)
- AuthenticationProvider (singleton)
MODEL
- Article
When the application first loads, execution will reach the ArticlesViewController's viewDidLoad method. In this method, I get a shared instance of the ArticleManager, specify the authentication class to be the authentication provider, and ask it for a list of recent articles.
// ArticlesViewController.m
-(void) viewDidLoad {
...
AuthenticationProvider *authProvider = [AuthenticationProvider sharedInstance];
[[ArticleManager sharedInstance] setAuthenticationProvider:authProvider];
[[ArticleManager sharedInstance] fetchNewArticles];
}
If no authentication was necessary, the ArticleManager would successfully retrieve the list from the server and post a notification letting anyone interested know that the articles have been retrieved. The ArticlesViewController would handle this notification:
// ArticlesViewController.m
- (void) handleNewArticlesNotification:(NSNotification *)note {
[self updateUI];
}
However, if authentication is required, the user needs to be presented with a login screen before the articles can be fetched and displayed. So I imagine the ArticleManager doing something like this:
// ArticleManager.m
- (void) fetchNewArticles {
if( [self.authenticationProvider isAuthenticated] ){
// go fetch list from the web
}
else {
[self.authenticationProvider presentAuthenticationRequest];
}
}
Now, at this point I run into some difficulty fleshing out the remainder of the details. The AuthenticationProvider could present the AuthenticationViewController as a modal view controller from the AppDelegate's window's rootViewController and AuthenticationProvider would be the delegate of AuthenticationViewController. The AuthenticationViewController would probably be dumb to the actual actions that it is taking, and would have it's delegate (AuthenticationProvider) do the work to authenticate the user. Once the user is authenticated, AuthenticationProvider would dismiss the modal view controller (AuthenticationViewController).
But how does ArticleManager get notified that the authentication that it requested has completed? It would need to be able to handle both successful and failed authentication attempts separately. A successful authentication would eventually result in fetchNewArticles being called again.
One thought is for ArticleManager to be a delegate of AuthenticationProvider. This seems to work in this case, but there are other Model Managers which could also rely on AuthenticationProvider. Presumably this would be resolved if AuthenticationProvider is not a singleton. Would that be a decent design approach?
Thanks for taking the time to help me understand a good design approach. I have coded this a couple of times, but always get stuck/confused toward the end. Also, if the entire approach needs to be re-architected, please feel free to point me in another direction.
Many thanks!
I have always used Global NSNotifications to post when a user has logged in or logged out. Every view controller that presents data differently can subscribe to those notifications and update themselves accordingly when an event happens.
This is nice, because you may already have other views (perhaps in other tabs) that have already loaded and will need to refresh when a user has logged in or out.
One thought is for ArticleManager to be a delegate of
AuthenticationProvider. This seems to work in this case, but there are
other Model Managers which could also rely on AuthenticationProvider.
Presumably this would be resolved if AuthenticationProvider is not a
singleton. Would that be a decent design approach?
Perhaps instead you could have the AuthenticationProvider singleton provide AuthenticationSession objects, set the caller as the delegate of the AuthenticationSession, and ask the AuthenticationSession to perform the authentication.

FBConnect delegate methods not called IOS

I just downloaded the facebook connect from github and none of the delegate methods are being called.
I even noticed that they did not assign the facebook.sessiondelegate = self in the viewdidload method. Therefore i assigned it but still no delegate methods called. This is really worrying because I am trying to get some user data and none of the call back methods are called.
Anyone knows why ?
Ok basically if it does the authentication via Safari, there is no way to get call backs. One way to solve this is force the in app login by forcing the trysafariauth = no .

How to receive UIAccessibilityNotifications in iPhone App

I'm interested in capturing UI changes in my application programmatically and thought that the UIAccessibility protocol may help. I've found how to post UIAccessibilityLayoutChangedNotification and UIAccessibilityScreenChangedNotification but I'm not sure how to register to receive these notifications.
I've tried using NSNotificationCenter, but the name param expects a string, while the two notifications above are of the type UIAccesibilityNotifications which is an int.
Any idea how to register for these notifications?
Thanks!
That's a great question! Unfortunately you cannot receive these "notifications" without affecting normal behavior. (i.e. "no you can't")
If you disassemble UIKit, you'll find UIAccessibilityPostNotification is implemented like this:
static void (*__UIAccessibilityBroadcastCallback)(UIAccessibilityNotifications notification, id argument);
void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument) {
__UIAccessibilityBroadcastCallback (notification, argument);
}
That means these accessibility "notifications" aren't any normal notifications. Rather, they are just parameters to an internal callback function. How the callback function is implemented depends on the accessibility bundle you're using.
You can replace the callback function with your own using the undocumented API _UIAccessibilitySetBroadcastCallback:
void _UIAccessibilitySetBroadcastCallback(void (*replacement)(UIAccessibilityNotifications notification, id argument)) {
__UIAccessibilityBroadcastCallback = replacement;
}
However, there isn't a corresponding "get" function (not even private), so once you set it, the original listeners cannot be notified again.

How do you use OAuth to Twitter from an iphone app?

I'm looking for a simple example of how to send a Tweet from an iphone app. I've seen some very complex methods, but it can't be that difficult. I have registered the app with twitter, so I have the key & secret. Just need to know where to put these so I can send a status update and have it say "sent from MyApp".
http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master
If you're using MGTwitterEngine you need to call the following method on your instance of MGTwitterEngine:
- (void)setClientName:(NSString *)name version:(NSString *)version URL:(NSString *)url token:(NSString *)token;
You might want to check out the version that explicitly supports OAuth.
MGTwitterEngine! Don't reinvent the wheel. Use either this (it's fantastically easy to use) or the CocoaRest library.