-
Notifications
You must be signed in to change notification settings - Fork 39
Tips and Tricks
This page contains a list of what I consider to be features specifically designed to make it a bit easier to write the application you want to make. Now that the base of the framework is in place, this is where most the attention will be.
All ADNKit model objects automatically support both NSCopying and NSCoding so that you can easily copy and archive!
If you are writing a native app (which if you're reading this, you probably are), you should be using username/password authentication. App.net [has a number of rules] (http://developers.app.net/docs/authentication/flows/password/#rules) surrounding this type of authentication when it comes to user security and privacy one of which is:
"Users MUST have a way to see which scopes are being requested by an application. This can be behind a “more info” button, but must at least be exposed on the login screen, before users are required to enter their password information to continue."
ANKClient has a class method designed to make fulfilling this requirement a little easier:
+ (NSArray *)scopeDescriptionsForScope:(ANKAuthScope)scope;
This will return an array of UI-appropriate statements using the same wording and terminology that App.net's auth email contains.
A very common task for App.net clients these days is determining if a given Post is a mention for the current user (you can fetch mentions separately, but when fetching the unified stream you just get a pile of Posts and there is no is_mention key to rely on).
Each ANKPost has an ANKEntities object representing which entities (mentions, links, and hashtags) the post has embedded in its content. Because of that, it's very easy to determine if a Post is a mention.
ANKPost has the following convenience method to help you out:
- (BOOL)containsMentionForUsername:(NSString *)username;
This one is very straight-forward. ANKChannel gives you the following convenience method:
- (BOOL)isPrivateMessageChannel
This determination is done using the channel's type property.
ANKEntities has a useful method that helps you turn text content + entities into an attributed string. This one is a bit of a mouthful:
- (NSAttributedString *)attributedStringForString:(NSString *)string
withDefaultAttributes:(NSDictionary *)defaultAttributes
mentionAttributes:(NSDictionary *)mentionAttributes
hashtagAttributes:(NSDictionary *)hashtagAttributes
linkAttributes:(NSDictionary *)linkAttributes
attributeEncodeBlock:(void (^)(NSMutableDictionary *attributes, ANKEntity *entity))encodeBlock;
The way you use this method is by passing in NSAttributedString-compatible attribute dictionaries for each of the three types of entities. There is also an optional attributeEncodeBlock, which will get called each individual entity that is encoded in the attributed string. The block is also passed a mutable attributes dictionary, which lets you modify the exact attributes that get applied to the text.
UPDATE: The following API has been removed due to incompatibility with iOS 5 and OS X 10.7. It will be added back to the framework when the minimum OS requirements can be bumped up. For now, you are free to use NSByteCountFormatter in your own app or format these in some other way. Sorry for any inconvenience!
ANKTokenStatus is a snapshot of information for the current user, and can be fetched via ANKClient's -fetchTokenStatusForCurrentUserWithCompletion. One interesting property to note is ANKTokenStatus's "storage" property, which contains information about used and remaining File storage for that user.
If you would like to display these values on the screen, you can easily get nicely formatted size strings using the following ANKStorage methods:
- (NSString *)formattedAvailableStorage;
- (NSString *)formattedUsedStorage;
This NSFormatter subclass is a convenient way to free users from dealing with the pesky '@' symbol at the beginning of usernames. NSTextField (on OS X) allows for an NSFormatter to be plugged in and applied as the user changes text. This would be a great candidate for use in a username field in an OS X app.
As per the [App.net documentation] (http://developers.app.net/docs/resources/user/#images), appending w and h GET parameters to the image URL allow you to fetch a dynamically resized image. ANKImage has a convenience method for this feature:
- (NSURL *)URLForSize:(CGSize)size;
Simply pass in the target size, and fetch the image from the returned URL instead of the ANKImage's URL property.