Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Tuesday, 6 April 2021

Sharing printers via AirPrint

I had been struggling to get my old Canon MP560 to work with my new Mac Mini running Bir Sur. I decided to use my Raspberry Pi 4 running Ubuntu Server 20.04 as a printer server and at the same time to see if I could finally get printing to work from my iPhone.

I discovered that it is relatively straight forward to setup printer sharing via AirPrint. I based my inital attempt on the Linux Magazine's atricle on setting up AirPrint but I have different settings for the cups configuration and didn't need to add the mime types. I also needed to adjust the firewall settings and get my printers working from Linux as I had not previously set them up for Linux, only for Windows and MacOS

CUPS installation

For the CUPS installation I used the following packages:

  • cups-bsd
  • avahi
  • printer-driver-gutenprint

I installed CUPS and the Gutenprint printer drivers (which include drivers for both my Canon MP560 and HP Laserjet 6P) using the following steps:

sudo apt-get update sudo apt-get install cups-bsd avahi-daemon printer-driver-gutenprint sudo systemctl start cups sudo systemctl enable cups

I then edited the CUPS configuration and changed only the bits shown below. I left the rest of the file alone.

# Only listen for connections from the local machine. Port 631 Listen /run/cups/cups.sock # Show shared printers on the local network. Browsing On BrowseLocalProtocols dnssd # Default authentication type, when authentication is required... DefaultAuthType Basic # Web interface setting... WebInterface Yes # Restrict access to the server... <Location /> Order allow,deny Allow @LOCAL </Location> # Restrict access to the admin pages... <Location /admin> AuthType Default Require valid-user Order allow,deny Allow @LOCAL </Location> # Restrict access to configuration files... <Location /admin/conf> AuthType Default Require user @SYSTEM Order allow,deny </Location>

I then configured the firewall to allow access to CUPS and Avahi. Note the network this setup is on is 192.168.200.0 as seen in the config below - change as required.

sudo ufw allow in from 192.168.200.0/24 to any port 631 sudo ufw allow 5353/udp

I then added any required users to the lpadmin group. eg sudo adduser XXX lpadmin before restarting CUPS (sudo systemctl restart cups) and starting and enabling avahi-daemon.

sudo systemctl start avahi-daemon sudo systemctl enable avahi-daemon sudo systemctl restart cups

I then connected to my Raspberry Pi on port 631 and used the CUPS admin interface to add my Canon MP560 and HP Laser 6P printers and checked that they worked by printing a test page for each.

AirPrint configuration

Once I had confirmed that the printers were setup and that the Raspberry Pi could successfully print from them, I used the 'airprint-generate.py' script from https://github.com/tjfontaine/airprint-generate/archive/refs/heads/master.zip to generate avahi service files. 'airprint-generate.py' has the following dependencies:

  • python3
  • python3-cups
sudo apt-get install python3 python3-cups unzip wget https://github.com/tjfontaine/airprint-generate/archive/refs/heads/master.zip unzip master.zip cd airprint-generate-master/ ./airprint-generate.py

Both of my printers were now visible to and usable from both my iPhone and Mac Mini.

Wednesday, 26 August 2020

Using configure scripts to make libraries for iOS

While building a wxWidgets app for iOS, I wanted to build wxWidgets as a library, not include it as part of the application as the minimal iOS example does. The following script (based on ios-autotools) sets up the required environment and then calls the supplied configure script.

    The main changes are:
  1. the configure script is passed as a parameter so that it does not need to be in the same directory as the iconfigure script which keeps the source folder unchanged
  2. if an SDK version is passed in and the SDK for that version of the SDK does not exist then the default SDK is used with the ios-min-version set to the specified version.
#!/bin/sh set -e usage () { echo "Usage: [VARIABLE...] $(basename $0) architecture path" echo "" echo " architecture Target architecture. [armv7|armv7s|arm64|i386|x86_64]" echo " path path to configure script to run" echo "" echo " VARIABLEs are:" echo " SDKVERSION Target a specific SDK version." echo " PREFIX Custom install prefix, useful for local installs." echo " CHOST Configure host, set if not deducable by ARCH." echo " SDK SDK target, set if not deducable by ARCH. [iphoneos|iphonesimulator]" echo "" echo " CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH" echo "" echo " All additional parameters are passed to the configure script." exit 1 } # Sanity checks if [ "$#" -lt 2 ]; then echo "Please supply an architecture name and configure file" usage fi # Build architecture export ARCH=$1 # Configure script CONFIG=$2 # Export supplied CHOST or deduce by ARCH if [ ! -z "$CHOST" ]; then export CHOST else case $ARCH in armv7 | armv7s ) export CHOST=arm-apple-darwin ;; arm64 ) export CHOST=aarch64-apple-darwin ;; i386 | x86_64 ) export CHOST=$ARCH-apple-darwin ;; * ) usage ;; esac fi # Export supplied SDK or deduce by ARCH if [ ! -z "$SDK" ]; then export SDK echo Using supplied SDK of "$SDK" else case $ARCH in armv7 | armv7s | arm64 ) export SDK=iphoneos ;; i386 | x86_64 ) export SDK=iphonesimulator ;; * ) usage ;; esac fi # Export supplied SDKVERSION or use system default if [ ! -z "$SDKVERSION" ]; then SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform) export SDKVERSION export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk" # If the SDK for the supplied version doesn't exist, use the current one if [ ! -d "$SDKROOT" ]; then export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version fi else export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version fi # Export supplied SDKVERSION or use system default if [ ! -z "$SDKVERSION" ]; then SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform) export SDKVERSION export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk" # If the SDK for the supplied version doesn't exist, use the current one if [ ! -d "$SDKROOT" ]; then export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version fi else export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version fi # Export supplied PREFIX or use default if [ ! -z "$PREFIX" ]; then export PREFIX else export PREFIX="/opt/$SDK-$SDKVERSION/$ARCH" fi # Binaries export CC=$(xcrun --sdk $SDK --find gcc) export CPP=$(xcrun --sdk $SDK --find gcc)" -E" export CXX=$(xcrun --sdk $SDK --find g++) export LD=$(xcrun --sdk $SDK --find ld) # Flags export CFLAGS="$CFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -mios-version-min=$SDKVERSION" export CPPFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -mios-version-min=$SDKVERSION" export CXXFLAGS="$CXXFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include" export LDFLAGS="$LDFLAGS -arch $ARCH -isysroot $SDKROOT -L$PREFIX/lib" export PKG_CONFIG_PATH="$PKG_CONFIG_PATH":"$SDKROOT/usr/lib/pkgconfig":"$PREFIX/lib/pkgconfig" echo CFLAGS="$CFLAGS" # Remove script parameters shift 2 # Run configure $CONFIG \ --prefix="$PREFIX" \ --host="$CHOST" \ $@

Sunday, 9 August 2020

Issues using wxWidgets on iOS

PNG files fail to load (in the Simulator - not tried a real device yet) using the 'builtin' PNG library

Warning: no bitmap handler for type 50 defined. Warning: CgBI: unhandled critical chunk Error: Couldn't load a PNG image - file is corrupted or not enough memory. Warning: Unknown image data format.

To fix set:

  • Compress PNG Files to NO
  • and
  • Remove Text Metadata From PNG Files to NO

Full screen

Currently wxWidgets doesn't support switching between full screen and non-full screen but I'm working on a patch.

To get fullscreen to work in the current version (3.1.5) you need to set your application to have a lanch screen storyboard and hide the status bar in the setting panel of the target application

Saturday, 8 August 2020

EXC_BAD_ACCESS code=50 when launching an iOS Application under the simulator

If you get an EXC_BAD_ACCESS error with code = 50 when running an iOS application under the simulator, disable the hardened runtime for the simulator

Enable Hardened Runtime > Debug > Any iOS Simulator SDK No. The compile options for real devices can be left on Yes.

Monday, 3 August 2020

Issues I have run into when building wxWidgets

Generally

  • If the (full?) directory name contains an apostrophe (') you get an error message along the lines of:
    syntax error near unexpected token '(' *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;'"
  • If the (full?) directory name contains a space the build will fail.

For iOS

  • The C and CPP flages -miphoneos-min-version need changing to -mios-min-version.

Sunday, 19 March 2017

Downloading Apple simulators manually

The other day I decided to download the latest tvOS simulator but the download via Xcode kept failing! I decided to try and download it manually. After a quick google I found that the URL of the download was displayed in the system console the you cancelled the download.

After copying the download URL into Safari, and also using curl via the command line, I had no better luck :(

To get the download to work successfully I found that I had to change the URL from https to http and it just worked! :)

The steps I followed are:

  1. Open XCode, open preferences, go to the Downloads section.
  2. Open the Console App, clear the console for your device (not strictly necessary but makes it easier to find the URL later).
  3. Go back to the XCode preferences. Start the simulator download, then cancel it.
  4. Now in the Console, you will see something about the cancellation with the download URL.
  5. Copy the URL from the Console. Then in Terminal in some suitable directory, download it: 

    curl http://[the url you copied] -O -R 
    (the letter O, not a zero)

  6. Finally, copy this file to ~/Library/Caches/com.apple.dt.Xcode/Downloads
  7. In XCode, in the Downloads section, start the Simulator download again, it should find the file you downloaded and install it.

Example:
robs-macbookpro:~ rob$ curl http://devimages-cdn.apple.com/downloads/xcode/simulators/com.apple.pkg.AppleTVSimulatorSDK10_0-10.0.1.1474488730.dmg -O -R
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1073M  100 1073M    0     0   601k      0  0:30:25  0:30:25 --:--:--  565k
robs-macbookpro:~ rob$ cp com.apple.pkg.AppleTVSimulatorSDK10_0-10.0.1.1474488730.dmg ~/Library/Caches/com.apple.dt.Xcode/Downloads/

Thursday, 27 January 2011

Setting the initial screen scaling in iPhone, iPod and iPad

To try and force the contents of a page to fit the width of an iPhone, iPod touch or iPad screen rather than scale the view to fit the window, add the following to the head section of an html page

<meta name="viewport" content="width=device-width" >