loading...
Cover image for How can my Titanium iOS app detect that a screenshot has been taken?

How can my Titanium iOS app detect that a screenshot has been taken?

brentonhouse profile image Brenton House ・2 min read

Ask-a-Geek: Answers to Frequently asked API and Mobile Questions (6 Part Series)

1) How do I add a custom font to my mobile app for iOS and Android? [SOLVED] 2) What are the best practices for architecting API authentication? 3 ... 4 3) API-First, Mobile-First, Design-First... How do I know where to start?? 4) How do I take a screenshot inside mobile app for iOS and Android? 5) How can my Titanium iOS app detect that a screenshot has been taken? 6) How do I add the Star Wars intro to my iOS and Android mobile apps?

Dear Geek,

Can I detect that a screenshot has been taken (like Snapchat does) on my Titanium mobile app for iOS?

  —   WATCHING FOR SCREENSHOTS

Dear Watching,

Good news! While there isn't a built-in way to detect that a screenshot has been taken, you can install this native module and get alerted any time a user takes a screenshot of your app.

Install @titanium/screenshot native mobile for Titanium SDK

run this in the root directory of your project

npm install @titanium/screenshot

Add code to listen for screenshot taken


// require the module
const screenshot_detective = require('@titanium/screenshot');

// add event listener
screenshot_detective.addEventListener('screenshotTaken', e => {
    console.debug('you are here → screenshot detected');
    alert('Screenshot taken!');
});

Limitations

  1. This only works with iOS. Android is more of a pain when it comes to screenshot detection.
  2. This will only detect screenshots taken with the physical buttons on the device (or with the simulator). It will not fire if you take a screenshot directly using the Titanium SDK.

You can find more information about detecting screenshots with Titanium Native mobile apps on the @titanium/screenshot npm page here.

About Brenton House
With 25 years of experience in the development world, Brenton House leads Developer Relations for Axway's API and mobile products, He has worked closely with many clients across various industries including broadcasting, advertising, retail, financial services, transportation, publishing, supply chain, and non-profits. Brenton's passion for everything API and mobile combined with his strategy and design experience, has enabled him to help developers create captivating products that inspire and delight audiences.

Ask-a-Geek-API-Mobile-Questions-Solved

Ask-a-Geek questions are answered by Brenton House, an API and Mobile geek who has been doing dev work for 25+ years.

Ask-a-Geek: Answers to Frequently asked API and Mobile Questions (6 Part Series)

1) How do I add a custom font to my mobile app for iOS and Android? [SOLVED] 2) What are the best practices for architecting API authentication? 3 ... 4 3) API-First, Mobile-First, Design-First... How do I know where to start?? 4) How do I take a screenshot inside mobile app for iOS and Android? 5) How can my Titanium iOS app detect that a screenshot has been taken? 6) How do I add the Star Wars intro to my iOS and Android mobile apps?

Posted on by:

brentonhouse profile

Brenton House

@brentonhouse

API and Mobile Strategist with 25+ years in dev community. Head #DevRel Geek at Axway and host of Breaking the Build YouTube series.

Discussion

markdown guide