Objective-C API for creating Mail/Message like receivers - objective-c

Does anyone know if there exists an open Apple API to use to create rounded receivers badges as you can see in both Mail and Message app (and probably several other Apple apps).
EDIT: An examplifying picture (I want to achieve the same effect as where it says "Jay Deragon")

The simplest way:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:99] //shows 99 on app icon

Related

NSApplication mainMenu returns nil

the problem I'm having is I cannot add a menu to my app programmatically!
here's where I'm at:
in app delegate
applicationDidFinishLaunching:
create a window and make key and order front.
EDIT:( here if I log [NSApplication sharedApplication].mainMenu prints (null) ) anyway...
create a NSMenu object and [[NSApplication sharedApplication] setMainMenu:myMenu]
also tried [[NSApplication sharedApplication] setMenu:myMenu]
build/run
menu is not there!
EDIT2:
( if still not understanding: )
make a osx app, remove the menu object, run, you'll still see a menu up there with the name of your app, you click it, it turns blue but no submenus, now how do I get a pointer to that!
You won't be able to do this as the OSX menus conform to the Aqua layout. Is there any reason why you'd remove it completely?
It's probably going to be a nightmare for a few reasons:
1) In the standard 'Aqua Menu' you have menu's like 'Services' which are handled by the system and not by the Application.
2) Apple are specific about their design guides, and menu's aren't mentioned and I'd HIGHLY doubt it apple would like you changing the Aqua layout.
I remember once upon a time coming upon a discussion which mentioned setAppleMenu etc... but that was back in the Tiger (I think) days.
edit you won't be able to get a 'pointer; to it using Documented API's, it's system-driven, not application driven i.e. complying with Aqua.
Personally, I'd remove all of the menuItems which can be changed in a sandboxed app, i.e. in User Land, and add/remove the various menuItems yourself.

How to add the iOS "Open In..." feature to an app

I would like to know how to present the "Open In..." Action Sheet (iPhone) / Popover (iPad) from my app, preferably an IBAction
I would hope that it'd be similar to declaring a file type then creating the view and opening the app selected by the user, but I know it is more complicated then that.
I realize that a similar question has been asked on StackOverflow, but I cannot make sense of the answer that was accepted: How to use "open in..." feature to iOS app?, and I have found some Apple Documentation on Document Interaction Programming. But, I can't really make sense of these.
Create a UIDocumentInteractionController by using the interactionControllerWithURL: class method (pass the URL of the file you want to open in another app).
Then call either presentOpenInMenuFromRect:inView:animated: or presentOpenInMenuFromBarButtonItem:animated:. The controller takes care of presenting the popover with available apps for that file type and opening the selected app.
If you want to know when the menu was dismissed and which app was selected, you need to implement the UIDocumentInteractionControllerDelegate protocol.
omz makes some good points on how to do that in his answer, however this procedure is much easier with the introduction of new APIs in iOS 6. Here's a simple and efficient way to show the UIActionSheet Open-In-Menu in iOS 6 and up:
NSArray *dataToShare = #[contentData]; //Or whatever data you want to share - does not need to be an NSArray
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
Also, if your app is compatible with versions of iOS lower than 6.0 you may want to check if the Share Service exists:
if ([UIActivityViewController class])
Once you present the sheet, iOS will automatically handle the rest for you. It will display a beautiful uiactionsheet with icons showing each app or service the user can open / share your data with:
Note that depending on the contents of the data, iOS will show different services in the Share Sheet
EDIT: The method above shares the file content, but not the file itself. Refer to omz's answer for more on that.
I've personally never had to do this, but your answer can most certainly be found in this Apple Documentation: http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html#//apple_ref/doc/uid/TP40010410-SW1.

Is it possible to request an APNS Device Token from the View Controler?

I'm new to Objective-C and iOS development, but I was wondering if there was a way to request an Apple Push Notification Device Token from the View Controller and store the token in a string to use later in a Query String sent to my web application.
I've been searching, but haven't been able to find a solution to this. Any help would be appreciated!
You should be able to call registerForRemoteNotificationTypes: anywhere in your code.
But you'll have to implement application:didRegisterForRemoteNotificationsWithDeviceToken: in your app delegate.
You can register for up to 3 different types of notification. Just remove and add as required.
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert | //Alerts are pop up boxes or on ios5, banners
UIRemoteNotificationTypeBadge | //Badges are the little red number on the icon
UIRemoteNotificationTypeSound)]; //Sounds are... well, sounds. These can be played when presenting a remote notification

Customized Buttons on a UIActionsheet

I am trying to create a UIActionsheet with several buttons as options.
Is it possible?.
If it is, will apple let in onto apps store. I have seen in some blogs that these types of windows are rejected?
if not possible is there an alternative to UIActionsheet, that will achieve similar functionallity?.
It is possible and I don't think Apple will reject it (why would they ?).
Action sheet is like a UIView you can add anything in that. Yes! you can create a UIActionsheet as you specified.
Apple will not be rejecting if it is customized. it may be due to some other issues.
Refer answer 1. Why cant you use a normal UIView.
To know more about UIActionsheet read the documentation

How do I draw a badge on my Dock icon using Cocoa?

How do I add a badge to the Dock icon for my app using Cocoa? Is there any roughly "standardized" way to do this?
(I'm referring to the kind of badges that show up in Mail, iChat etc. to indicate the number of unread messages and the like.)
Cocoa Touch does provide one such method, but I haven't been able to find any equivalent for a regular Cocoa application.
Use
[[[NSApplication sharedApplication] dockTile] setBadgeLabel:#"2234"];
This method, and the NSDockTile class, has been available since Leopard.
It should be noted that NSDockTile is only available on Leopard. If you need to target Tiger you'll need to use -setApplicationIconImage: on your NSApplication object and draw your badge by hand.
Also, it's not in the documentation outside of the release notes that I could find but you get your application's dock tile by sending the dockTile message to your NSApplication object.
NSDockTile *tile = [[NSApplication sharedApplication] dockTile];
[tile setBadgeLabel:#"Lots"];
A quick google search turned up the NSDockTile class. Seems pretty self-explanatory once you take a gander at the documentation.