How to solve Safari PDF first page problem for Apple iPhone and iPad?

Render a PDF file using your iPhone, it may seem like an easy operation but I had a bit of trouble doing it via Safari for iPhone and iPad.

Unfortunately only the first page of the PDF was shown, the rest was blocked. πŸ€ͺ

What is the recommended way to render PDF in HTML?

  • iFrame ❌
  • Object ❌
  • Embed ❌
  • PDF.JS library ❌
  • Google PDF viewer ❌

I tried all online solutions and PDF plugins but always same result:

  • Desktop: Chrome, Opera, Firefox working βœ…
  • iOS: Safari not working ❌

So how to solve Safari PDF first page problem for Apple iPhone and iPad?

Using Javascript you can Decode base64 string, create a blob object with content-type “application/pdf” and navigates the browser to pdf.

Thanks for reading! 🌟

How to localize info.plist in Xcode

As you know with iOS 14 Apple requires consent to access the IDFA (Identifier for Advertisers), you need to display the App Tracking Transparency authorization request for accessing the IDFA. How to implement this change? Just update your Info.plist and add the NSUserTrackingUsageDescription key with a custom message describing your usage. My app supports more languages and the info.plist file is only one… πŸ€”

How to localize info.plist in Xcode ?

<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>

I read a lot of articles about automatically localize the info.plist file but i had several problems. The easiest solution was to:

  • Add in the project a new Strings file InfoPlist.strings (case sensitive), I’ve already written it but I want to repeat it otherwise it won’t work. You need to create the InfoPlist.strings file, not Infoplist.strings or infoPlist.strings.
  • Open the InfoPlist.strings file and add your keys and custom descriptions.
"NSUserTrackingUsageDescription" = "My app will use this identifier to provide you with personalized ads.";
  • Select the InfoPlist.strings and use the Localization section in the File Inspector to localize the file. Press the Localize… button to add additional Localizations to your app.
  • Run the simulator in each languages and this will work πŸ‘

 

If you think your friends/network would find this useful, please share it with them. I’d really appreciate it.

Thanks for reading! 🌟

 

Reference: About Information Property List Files

How to Take a Screenshot or Record a Video using the iOS Simulator

As an iOSΒ  to show my project or to publish an app on the AppStore I need to take screenshots or to record a video.

The first idea was to use the Simulator and press the button Save Screen when i need, for the video to use QuickTime Player, you can follow this link to understand how to do.

I’ve been using the xcrun command for some time and now I feel comfortable with it. You can automate it by creating a script.

What is xcrum command ?

xcrun is a tool provided by Apple to run any tool inside Xcode from the command line, usually it’s available with the installation of xcode but you can get downloading the Command Line Tools package from the Developer website. The Command Line Tools package is available for download on the Download for Apple Developers page. Log in with your Apple ID, then search and download the Command Line Tools package appropriate for your machine

How to Take a Screenshot with xcrum ?

  1. Run your app in the Simulator.
  2. Launch Terminal.app (in /Applications/Utilities) and run this command:

1
xcrun simctl io booted screenshot screenshot.png

xcrun simctl io booted screenshot screenshot.png

There are several option to use with this command to improve your screenshot:

  • –type
    • Can be “png”, “tiff”, “bmp”, “gif”, “jpeg”. Default is png.
  • –display
    • iOS: supports “internal” or “external”. Default is “internal”
    • tvOS: supports only “external.
    • watchOS: supports only “internal.
  • –mask
    • You may also specify a port by UUID. For non-rectangular displays, handle the mask by policy:
      • ignored: The mask is ignored and the unmasked framebuffer is saved.
      • alpha: The mask is used as premultiplied alpha.
      • black: The mask is rendered black.

How to Record a Video with xcrum ?

  1. Run your app in the Simulator.
  2. Launch Terminal.app (in /Applications/Utilities) and run this command:

1
xcrun simctl io booted recordVideo video.mov

There are several option to use with this command to improve your video:

  • –codec
    • Specifies the codec type: “h264” or “hevc”. Default is “hevc”.
  • –display
    • iOS: supports “internal” or “external”. Default is “internal”
    • tvOS: supports only “external.
    • watchOS: supports only “internal.
  • –mask
    • For non-rectangular displays, handle the mask by policy:
      • ignored: The mask is ignored and the unmasked framebuffer is saved.
      • alpha: Not supported, but retained for compatibility; the mask is rendered black.
      • black: The mask is rendered black.
  • –force
    • Force the output file to be written to, even if the file already exists.

 

If you think your friends/network would find this useful, please share it with them. I’d really appreciate it.

Thanks for reading! 🌟