Skip to content

Instantly share code, notes, and snippets.

Peter Steinberger steipete

Block or report user

Report or block steipete

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AppKitHelper.m
@implementation UIImage (ResourceProxyHack)
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format {
// HACK: proxy seems garbage so we always show PDF for now.
let cgImage = [_bridge imageForFileType:@"pdf"];
// HACK: We use mainScreen here but could have multiple screens.
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
return image;
}
View AppKitHelper.m
@implementation UIImage (ResourceProxyHack)
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format {
// HACK: proxy seems garbage so we always show PDF for now.
let cgImage = [_bridge imageForFileType:@"pdf"];
// HACK: We use mainScreen here but could have multiple screens.
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
return image;
}
@steipete
steipete / UIScreenDebugLLDB.txt
Last active Oct 10, 2019
UIScreen on Catalyst is.. weird (tested with 10.15.0 GM). Reported as FB7364971
View UIScreenDebugLLDB.txt
(lldb) po UIScreen.mainScreen
<UIScreen: 0x119905f10; bounds = {{0, 0}, {960, 540}}; mode = <UIScreenMode: 0x600000290300; size = 1920.000000 x 1080.000000>>
Display: 15,4-inch (2880 x 1800)
Scaling set to max, so effectively 1920x1200 (virtual screen of 3840x2400)
What I would expect: <UIScreen bounds = {{0, 0}, {1920, 1200}}; mode = <UIScreenMode: 0x600000290300; size = 3840.000000 x 2400.000000>>
------
@steipete
steipete / PSPDFCatalystPatches.m
Last active Oct 19, 2019
Fixes Mac Catalyst: random crash inside [_UIBlurEffectCoreUIImpl _needsUpdateForTransitionFromEnvironment:toEnvironment:usage:] ()
View PSPDFCatalystPatches.m
Use this code: (code incomplete, but you get the idea what needs to be done)
// TODO: Stop calling this once 10.15.1 is out!
#if TARGET_OS_UIKITFORMAC
static void PSPDFFixVisualEffectsEnvironment(void) {
static const char *PSPDFVisualEffectsWindowKey;
static const char *PSPDFVisualEffectsSuperviewKey;
let klass = NSClassFromString([NSString stringWithFormat:@"_%@sualEffe%@ironment", @"UIVi", @"ctEnv"]);
@steipete
steipete / HowToUseURLByResolvingBookmarkDataOnMacCatalyst.md
Last active Nov 8, 2019
Using URLByResolvingBookmarkData on Mac Catalyst: Access sandboxed URLs after an app restart.
View HowToUseURLByResolvingBookmarkDataOnMacCatalyst.md

Here's what needs to be done in order to use security scoped bookmarks on Mac Catalyst:

  1. You need an entitlement: "com.apple.security.files.bookmarks.app-scope" needs to be se to 1.

  2. Pass both NSURLBookmarkCreationWithSecurityScope and NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess when creating the bookmark.

Note: The headers mark these API as unavailable for iOS, and this indeed does only work on Mac and not iOS. However, Mac Catalyst really is a Mac app, so using these values is fine. In order to allow compilation, use following:

@steipete
steipete / UIView+AnimationContext.swift
Created Aug 10, 2019 — forked from CodingMeSwiftly/UIView+AnimationContext.swift
An extension on UIView to retrieve information about the animation context the view is currently in.
View UIView+AnimationContext.swift
import UIKit
extension UIView {
struct AnimationContext {
public let duration: TimeInterval
public let timingParameters: UITimingCurveProvider?
}
}
extension UIView {
@steipete
steipete / UIView+AnimationContext.swift
Created Aug 10, 2019 — forked from CodingMeSwiftly/UIView+AnimationContext.swift
An extension on UIView to retrieve information about the animation context the view is currently in.
View UIView+AnimationContext.swift
import UIKit
extension UIView {
struct AnimationContext {
public let duration: TimeInterval
public let timingParameters: UITimingCurveProvider?
}
}
extension UIView {
@steipete
steipete / Runtime.m
Created Aug 7, 2019
pspdf_swizzleSelectorWithBlock, pspdf_swizzleSelector. Please use your own prefix when you copy these.
View Runtime.m
// http://defagos.github.io/yet_another_article_about_method_swizzling/ (Thank you!!)
// Returns the original implementation
static _Nullable IMP pspdf_swizzleSelector(Class clazz, SEL selector, IMP newImplementation) {
NSCParameterAssert(clazz);
NSCParameterAssert(selector);
NSCParameterAssert(newImplementation);
// If the method does not exist for this class, do nothing.
const Method method = class_getInstanceMethod(clazz, selector);
if (!method) {
@steipete
steipete / SomeObjCFile.m
Created Aug 7, 2019
HACK around FB6940492: Mac Catalyst: Crash when presenting view controllers. Call early.
View SomeObjCFile.m
/**
HACK around FB6940492: Mac Catalyst: Crash when presenting view controllers
'NSRangeException', reason: 'Cannot remove an observer <UINSSceneViewController 0x600003558790> for the key path "view.window.screen.contentLayoutRect" from <UINSSceneViewController 0x600003558790> because it is not registered as an observer.'
0 CoreFoundation 0x00007fff3b20f183 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff71719b64 objc_exception_throw + 48
2 Foundation 0x00007fff3d8ca2aa -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 578
3 Foundation 0x00007fff3d8ca01b -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 74
4 Foundation 0x00007fff3d8e2898 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 190
@steipete
steipete / UIWindow+PSPDFAdditions.h
Last active Dec 4, 2019
Mac Catalyst: Get the NSWindow from a UIWindow
View UIWindow+PSPDFAdditions.h
// Don't forget to prefix your category!
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIWindow (PSPDFAdditions)
#if TARGET_OS_UIKITFORMAC
You can’t perform that action at this time.