Skip to content

Instantly share code, notes, and snippets.

@johnnyclem
johnnyclem / CyanifyOperation.swift
Created September 23, 2015 22:04
Defines a subclass of NSOperation that adjusts the color of a video file.
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
Defines a subclass of NSOperation that adjusts the color of a video file.
*/
import AVFoundation
import Dispatch
(pv -n $INPUT_DISK_IMAGE | dd of=/dev/$OUTPUT_DISK_ID bs=2m conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
Here is what you need to do to register your app for a custom URL scheme (for the example we will use a "myapp" scheme).
1) In your Info.plist, add a new entry for CFBundleURLTypes: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>MyApp's URL</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
2) Somewhere in your application's startup code (e.g. init), add this code: - (void)registerMyApp { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; }
- (void)getUrl:(NSAppleEventDescriptor )event withReplyEvent:(NSAppleEventDescriptor )replyEvent { NSString url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; // Now you can parse the URL and perform whatever action is needed }
Related Tidbits:
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestCaseRun.h
SENTEST_EXPORT NSString * const SenTestCaseDidStartNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidStopNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidFailNotification;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestDistributedNotifier.h
SENTEST_EXPORT NSString * const SenTestNotificationIdentifierKey;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestSuiteRun.h
SENTEST_EXPORT NSString * const SenTestSuiteDidStartNotification;
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(
self,
selector: "textFieldTextChanged:",
name:UITextFieldTextDidChangeNotification,
object: nil
)
func textFieldTextChanged(sender : AnyObject) {
sendButton.enabled = messageField.text.utf16count > 0
@johnnyclem
johnnyclem / gist:11015360
Created April 17, 2014 22:35
CMSamplebufferRef to CIImage
CVImageBufferRef cvImage = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvImage];
//
// NSArray+BinarySearch.h
// BinarySearch
//
// Created by Ole Begemann on 19.04.10.
// Copyright 2010 Ole Begemann. All rights reserved.
//
#import <Foundation/Foundation.h>
@johnnyclem
johnnyclem / iOS Camera - Highest Framerate
Last active May 18, 2018 05:32
this method sets the camera frame rate to the max available for the device
- (void)configureCameraForHighestFrameRate:(AVCaptureDevice *)device
{
AVCaptureDeviceFormat *bestFormat = nil;
AVFrameRateRange *bestFrameRateRange = nil;
for ( AVCaptureDeviceFormat *format in [device formats] ) {
for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) {
if ( range.maxFrameRate > bestFrameRateRange.maxFrameRate ) {
bestFormat = format;
bestFrameRateRange = range;
}
@johnnyclem
johnnyclem / gist:8215415
Created January 2, 2014 05:31
End the tyranny of UITextFields not resigning first responder when you expect them to, simply add this method to any UIViewController and keyboards will disappear whenever the user touches anywhere other than the keyboard itself or another UITextField
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIControl *control in self.view.subviews) {
if ([control isKindOfClass:[UITextField class]]) {
[control endEditing:YES];
}
}
}