You’ve downloaded the Force.com Toolkit for iOS and built your first app, now take it to the next level by adding media attachments from your device and real-time push notifications! Join Mavens Consulting for a code-intensive walk through of the open source Salesforce Case Memo app. You’ll learn how to record audio and upload it as an Attachment to a Case in a background thread. Next, integrate real-time push notifications with Apex trigger callouts to Urban Airship’s REST API. Finally, see how these techniques are used to meet real business requirements in 2nd Opinion, a bespoke Salesforce iPhone app for doctors to manage their relationships with pharmaceutical companies.
Beyond the Force.com Toolkit for iOS - Dreamforce 2011
1. Beyond the Force.com Toolkit for iOS Developers Track Matthew Botos, Mavens Consulting @BotosCloud We’re Hiring! Download the code! github.com/mbotos/CaseMemo
2. Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended April 30, 2011. This documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
3.
4. We’re Going to Build an iPad App View list of Cases with details Record, upload, & play audio Attachment Push notification of closed Cases
47. Push Log Sending to https://go.urbanairship.com/api/push/batch/: [{"aps": {"alert": "Your case has been closed”… System.HttpResponse[Status=OK, StatusCode=200]
53. Beyond Where We Started Open Source. OAuth. Keychain Secure Storage. Incremental Loading. Audio Recording. Audio Playback. Push Notifications.
54. Thanks for goingBeyond the Force.com Toolkit for iOS! Matthew Botos @BotosCloud We’re Hiring! Download the code! github.com/mbotos/CaseMemo
55. But wait, the DevZone has more! Hackathon Check out the Finale, Thurs, 2:30pm Open Source Lab Discover new & interesting open projects Lightning Forum Drop in for a quick blast of knowledge Tech Demos See and learn the latest from the experts Code Consultations Sign up for 1:1 sessions at the Welcome Desk @forcedotcom
56. How Could Dreamforce Be Even Better? Tell Us! Every session survey you submit is a chance to win an iPad 2! Watch your inbox at the end of each day for an email from our survey partner, Alliance Tech. Click on the personalized link to be directed to the survey page for the sessions you attended.
Notas do Editor
Download the code: http://github.com/mbotos/CaseMemoChatter for Session: https://dreamevent.my.salesforce.com/a093000000BtXA1 Contact Matthew Botos on Twitter: http://twitter.com/BotosCloudJoin the team at Mavens Consulting: http://mavens.force.com/careers
This is our safe harbor statement which if you cannot read, you can find on our website. Now let’s see what’s possible with Salesforce + iOS…
Off-label usage – treat a condition not explicitly approved by the FDADoctor views drug information on iPhoneDictates a question using a voice recordingReceives a push notification when answeredhttp://mavens.force.com/platform#mobile
Start asking level questions:How many people have an iPhone?And an iPad?More devices than Benioff?How many people understand this next slide? …
Basic steps covered in presentation and code comments; don’t worry, you can build it from scratch!Will focus on advanced tips and tricks, even within the steps covered
Like ReidCarlberg’sForceDotCom Labs Apps, this one is open source!Apache 2.0 LicenseYou’re free to download it, learn it, and reuse it in other free or commercial appsI’ll be talking more about Open Source Wednesday afternoon 2:30-3 in the GitHub Open Source LabThis is the last link you will see on the screen; others are in the speaker notes for reference
This is how you can tell it’s going to be a technical presentation…http://developer.force.com
http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_Toolkit_for_iOSIf you set the callback URL to https://login.salesforce.com/services/oauth2/success, then the iOS toolkit will be able to automatically renew the session key at regular intervals to keep the user logged in. Callback URL can also be “oob” – “out of band” for mobile (?)
https://github.com/developerforce/Force.com-Toolkit-for-iOSIn Xcode, search for “STEP 1” – results in line order, not alphabeticaloAuthViewController and callbackNeed to create regular Salesforce user who can login from anywhere without Salesforce admin IP restrictionsMUST whitelist IP rangesProfessional Edition users need additional API license
RootViewControllerloadDataButton label is in DetailViewControllerSplitViewDelegateTitle of popover is in MainWindow.xibSplitViewControllerAdd where/limit to show best practice of bounding queries for performanceFieldValue uses API name
It’s a pain to login every time!(Especially if you’re building for non-business Customer Portal users)Let’s store our OAuth token so we don’t’ have toQUESTION: Where could we store it? How secure is that location?
Built-in, powerful, kind of a pain to useFortunately there are open source wrapper libraries like ObjectiveKeychain - https://github.com/AquaGeek/ObjectiveKeychainTIP: If the native library is awkward, look for an existing open source wrapperLicense of third-party libraries in folder or headerFrom Step 1:Need to create regular Salesforce user who can login from anywhere without Salesforce admin IP restrictionsMUST whitelist IP rangesFiller Questions:What not store in other places?What about storage of SF data?What if we login with user/pass?
Already have detailed data (it wasn’t that much to just grab it all)Detail View XIB: add labels; drag connectors to Detail View Controller header to create propertiesImplement Detail View Controller configureViewCase list is a TableView, so implement RootView Controller didSelectRowAtIndexPath
Display Attachments for Case in TableViewAsynchronous load to avoid delaying overall page load – metadata only since bodies may be largeTIP: Always load asynchronously and think about which data to lazy load
With attachments
Without attachments
Only make network call if needed – how can we do this without querying the Attachments?Display loading indicator using MBProgressHUD wrapper around ActivityIndicator: https://github.com/matej/MBProgressHUDAlso clear Case detail placeholders and display loading indicator until loadedAlso implement conditional loading of attachmentsAttachments loading indicator using custom TableView section header in DetailViewAttachmentsHeadernib
Add custom field to Cases with Attachment count, update with trigger on Attachment, initialize with CaseAttachmentCount.updateAllCases();(Can’t do a rollup summary since Attachment uses a generic ParentId instead of an explicit relationship)
Loading Cases
Loading Attachments
Attachments loaded
Use AudioSession to record to a temporary fileFormat settings are limited for recording; these were found to be efficient for voice memosQuestions:What about the lag (In simulator)?
Create ZKSObjectShow in local datastore; don’t need to wait on a Salesforce refreshInsert asynchronously in SalesforceQuestions:Other media types – photos, video?Other parent objects, including custom?
Audio Memo added to attachments list
Attachment created in Salesforce
Get audio body (lazy-loading) with indicatorTo get body for newly created attachments, set id from create resultStart audio playbackDeselect row when doneOnly get audio attachmentsQuestions:Where can I get that progress indicator?
Use case: notify when any Case I’ve recorded a memo for is closed
Native Apple Push Notification Service (APNS) interface is difficult to use (odd port, binary format)Use Urban Airship REST API instead – free account tierhttp://urbanairship.com/
For this, you will need a physical iPad device and an Apple iOS developer accountApple Summary:Create new App IDConfigure to Enable Push Notifications and generate Certificate for server to send pushesDetails:http://mobiforge.com/developing/story/programming-apple-push-notification-serviceshttp://urbanairship.com/ - Create account, app, and upload the push certificate you downloaded from AppleNote difference between Development and Production push!Also need to add Code Signing Entitlements file to Xcode.
App must prompt user to allow notifications (opt-in)Store device token in Salesforce with link to User so we can address it laterTrigger on Mobile Device fills in current User Id and enforces uniquenessCreate Custom Profile for Demo User and enable Read, Create permissions for Mobile Device
Add permissions to custom Profile
QUESTION: What Salesforce features might we use?
Why have two implementations?TIP: Use a mock implementation of external web services for testing
Setup:Add Remote SiteAdd Custom Settings with Urban Airship keysKey identifies the application to Urban AirshipSecret is for use in mobile appsMaster secret is for use in remote servers
If errors, check Urban Airship Error Console
Inactive device token = user deleted app or turned off notifications
10 as of Summer 11
I was hoping this would be the new Salesforce mascot, but…Only 10 web callouts per contextBatch into a single UrbanAirship call for multiple Cases or Devices that require notificationTIP: Always design for bulk operations
By default, iOS will just take you to the applicationBy including custom userInfo in alert, we can indicate where we want to go, ie. specific Case IdImplement didReceiveRemoteNotification (if running)Check for notification in didFinishLaunchingWithOptions (if launching fresh from notification)STEP 10 e – jumping to case is in next methodQuestion:What’s necessary to deploy from sandbox to production?
How to use with another object – ie. AccountWhat does iOS toolkit give us out of box?Could you do this with HTML5? Push/audio