Skip to content →

Category: iOS

UIDocumentInteractionController vs UIActivityViewController

When I first released WebPDF, I used an UIActivityViewController to share the PDF. This only gave me a few apps to share to. I expected to see other apps that supported PDFs. Here is the code I used:

NSString* fileName = [NSString stringWithFormat:@"%@.pdf", 
  [self.detailItem valueForKey:@"pdfFilename"]];
NSString* filePath = [WebPDFUtils pathWithFilename:fileName];
NSArray *activityItems = @[[NSURL fileURLWithPath:filePath]];
    
UIActivityViewController *activityViewController = 
  [[UIActivityViewController alloc] initWithActivityItems:activityItems 
                                    applicationActivities:nil];
activityViewController.popoverPresentationController.barButtonItem = _shareButton;
    
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
  [self dismissViewControllerAnimated:YES completion:nil];
}];
    
[self presentViewController:activityViewController
                   animated:YES
                 completion:nil];

Here is what the share sheet looked like:
UIActivityViewController

After searching around I found the UIDocumentInteractionController. I updated my code:

NSString* fileName = [NSString stringWithFormat:@"%@.pdf", 
  [self.detailItem valueForKey:@"pdfFilename"]];
NSString* filePath = [WebPDFUtils pathWithFilename:fileName];
self.documentInteractionController = [UIDocumentInteractionController 
  interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
self.documentInteractionController.delegate = self;
self.documentInteractionController.UTI = @"com.adobe.pdf";
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:sender 
                                                               animated:YES];

Here is what the share sheet looked like:
UIDocumentInteractionController

When should you use a UIActivityViewController vs a UIDocumentInteractionController. You should really read the Developer docs:

UIActivityViewController

The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

UIDocumentInteractionController

A document interaction controller, along with a delegate object, provides in-app support for managing user interactions with files in the local system. For example, an email program might use this class to allow the user to preview attachments and open them in other apps. Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file.

In general if you’re sharing an image or url, you might want to use a UIActivityViewController. If you’re sharing a document, you might want to use a UIDocumentInteractionController.

Comments closed

WebPDF 1.1.0

me_icon
WebPDF has been updated to include support for saving a PDF from Safari.

In Safari, choose the share icon. Then tap on WebPDF. The page is saved as a PDF to WebPDF.

Source is available on GitHUB: https://github.com/dougdiego/WebPDF

Comments closed

WebPDF 1.0.0

me_icon
I needed an application that could create a PDF out of a webpage. I found a few apps on the AppStore, but none of them met my needs. I figured it would be a fun project and created WebPDF.

It’s a simple application that creates PDF’s out of webpages. The app saves the PDF, lets you view it and export it. It’s optimized for all iPhones (including the iPhone 6 and iPhone 6+) and the iPad.

I also made the source available on GitHUB: https://github.com/dougdiego/WebPDF

Comments closed

Xcode 6 Prefix Header

Prior to Xcode 6, all new projects contained a prefix header.  In Xcode 6 a prefix header is no longer included in the default project. Instead of using a prefix header you should put your imports in the files that need them.  But in the case that you need one, you can still add one.

From the menu, select File > New > File…

xcode6_prefixHeader1

 

Choose iOS > Other > PCH File

xcode6_prefixHeader2

 

In the Build Settings, each for “prefix” to narrow down your choices.  Under “Apple LLVM 6.0 – Language” find “Prefix Header”.  Add “$(SRCROOT)/PrefixHeader.pch”.  Make sure the path is correct.  When you close the dialog, it shows the expanded path.

xcode6_prefixHeader3

 

Comments closed

Xcode 6 category

After updating to Xcode 6, I thought Apple removed the ability to create a category when creating a new file. I was wrong. They just moved it.

To create a category in Xcode 6, choose File > New > File
xcode6_category1

 

Then select iOS > Source > Objective-C File

xcode6_category2

 

Choose File Type: Category.  Then enter you File name and the class you want to create a category for.

xcode6_category3

Comments closed

How to get the main storyboard

Here’s how to get at the main storyboard from inside your view controller.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] 
bundle:[NSBundle mainBundle]];

Most of the time you can just use self.storyboard. But if you are in a view controller that was not created by a storyboard, then self.storyboard will be nil.

Comments closed

Unable to determine simulator device to boot.

I’ve gotten this message “Unable to determine simulator device to boot.” a few times when trying to run my app in the iOS Simulator.  Unable to determine simulator device to boot. Each time it took me awhile to remember what it meant.

I’ve been working on updating an app to iOS8 and using Xcode 6.    Occasionally I need to run the current version and I start up Xcode 5.   When trying to run the app in the simulator I see this error.

The reason for the error is because the Xcode 6 simulator is already running and it doesn’t know which one to use.  simulator_in_dock

The solution is simple.  Just quit both simulators and try again run again.

 

 

Comments closed

WWDC 2014 – iOS Developer Wish list

As an iOS developer, here are a few things I’d like to see at WWDC 2014

  • Siri Extensibility – I’d like to see Apple open up Siri to third party apps.  For example if I have RunKeeper on my iPhone, I’d like to be able to tell Siri “Start my run”, “End my run”.
  • Blocks added to older API’s – A lot of older API’s are using delegates instead of completion blocks.  For example: UIAlertView
  • UIActivityViewController enhancements – Every time I’ve used UIActivityViewController, I’ve had to extend it to do what I wanted.  It shouldn’t be that hard to share an email where you can specific the recipient, subject, attachment, body, etc..
  • Inter App Communication – I’d like to see something more like Intents on Android.
  • AppleTV SDK – I’d love to be able to write apps for the AppleTV
  • Filesystem – Mac OS X and iOS are due for a new filesystem. ZFS was rumored for awhile but fell through.
  • Multi User iOS – It would be nice if iOS support multiple users, so a family could share an iPad.
Comments closed

ld: library not found for -lPods

I’ve had this error a few times, so I figured I’d document the solution for the next time it occurred.

When doing a build in Xcode, I got the following error:

ld: library not found for -lPods

My project is setup to use cocoapods.

First make sure you are using MyProject.xcworkspace and not MyProject.xcodeproj

For me this was the case.  But I realized that I just created a new configuration for “Ad Hoc” builds.  To fix the problem I had to install the Podfile again with the command:

pod install

After running pod infall, open the project: MyProject.xcworkspace, clean your project and build.  The error should go away.

Comments closed

AddressBookFiller for iOS

AddressBookFiller is a simple application which populates your address book with contacts. It is an updated version of my previous post.

This is useful when developing for the iOS and working on the emulator. On many occasions, I’ve spent quite a bit of time adding contacts to the emulator to test something. Then when I change emulator version, they all get erased. This is very frustrating. So I put together this simple application which allow you to programatically fill up your address book.

Currenly the address book is populated with U.S. Presidents. Values are set for:
* first name
* last name
* photo
* phone number
* birthday
* Address: street, city, state, zip

Source on Github: https://github.com/dougdiego/AddressBookFiller

Comments closed