Skip to content

Instantly share code, notes, and snippets.

View baileysh9's full-sized avatar

Scott Bailey baileysh9

View GitHub Profile
@baileysh9
baileysh9 / saveLogin.swift
Last active September 17, 2015 14:24
Save Login Keychain Swift
func saveLogin(password: NSData, userName:String, service:String)
{
//Create the query
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, userName, password], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecValueDataValue])
// Delete any existing items
SecItemDelete(keychainQuery as CFDictionaryRef)
//Add the query to the keychain
let status: OSStatus = SecItemAdd(keychainQuery as CFDictionaryRef, nil)
@baileysh9
baileysh9 / loadLogin.swift
Last active September 17, 2015 14:30
Load Login from Keychain Swift
func load(service: NSString, userName:String) -> NSString?
{
//Create the query keychain
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, userName, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecReturnDataValue, kSecMatchLimitValue])
var dataTypeRef : Unmanaged<AnyObject>?
// Search for the keychain items
let status: OSStatus = withUnsafeMutablePointer(&dataTypeRef) { SecItemCopyMatching(keychainQuery as CFDictionaryRef, UnsafeMutablePointer($0)) }
@baileysh9
baileysh9 / Receipt_validation_prt1.swift
Last active February 9, 2017 17:18
Reading in receipt Prt 1 in Swift
//Get the Path to the receipt
let receiptUrl = Bundle.main.appStoreReceiptURL //Swift2 : NSBundle.mainBundle().appStoreReceiptURL
//Check if it's actually there
if FileManager.default.fileExists(atPath: receiptUrl!.path) //Swift 2: NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!)
{
//Load in the receipt
//Swift 2: let receipt: NSData = try! NSData(contentsOfURL:receiptUrl!, options: [])
//Swift 3
let receipt: Data = try! Data(contentsOf: receiptUrl!, options: [])
@baileysh9
baileysh9 / Parsing_Receipt.swift
Last active February 9, 2017 16:44
Parsing Receipt in Swift
//Swift 2
//let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).memory.contents)
//var ptr = UnsafePointer<UInt8>(octets.memory.data)
//let end = ptr.advancedBy(Int(octets.memory.length))
//Swift 3
let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).pointee.contents)
var ptr = UnsafePointer<UInt8>(octets?.pointee.data)
let end = ptr?.advanced(by: Int((octets?.pointee.length)!))
@baileysh9
baileysh9 / Parsing_productids.swift
Last active February 17, 2017 17:05
Parsing Product Ids from Receipt in Swift
func getProductIdFromReceipt(_ data:Data) -> String? //Swift 2: func getProductIdFromReceipt(data:NSData) -> String?
{
//Swift 2: var p = UnsafePointer<UInt8>(data.bytes)
//Swift 3
var p : UnsafePointer? = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
let dataLength = data.length
var type:Int32 = 0
var tag:Int32 = 0
@baileysh9
baileysh9 / iOS_receipt
Created October 30, 2015 18:42
iOS In App Purchase Receipt
{
environment = Sandbox;
receipt = {
"adam_id" = 0;
"app_item_id" = 0;
"application_version" = 1;
"bundle_id" = "com.yourcompany.yourapp";
"download_id" = 0;
"in_app" = (
{
@baileysh9
baileysh9 / MobileInput.cs
Last active April 1, 2016 16:11
Unity Mobile Input
void Update () {
if (Input.touchCount == 1) {
//Get the player and camera objects
GameObject player = GameObject.FindGameObjectWithTag ("Player");
GameObject camera = GameObject.FindGameObjectWithTag ("MainCamera");
//Change the character's position by moving in the direction that the camera is facing
player.transform.position = player.transform.position + camera.transform.forward;
}
namespace CocosDemo
{
public class App : Application
{
static public int ScreenHeight;
static public int ScreenWidth;
public App ()
{
// The root page of your application
@baileysh9
baileysh9 / iOSScreenDim.cs
Created April 29, 2016 17:44
iOSScreenDim
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init ();
// Code for starting up the Xamarin Test Cloud Agent
#if ENABLE_TEST_CLOUD
Xamarin.Calabash.Start();
#endif
App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
var metrics = Resources.DisplayMetrics;
var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);
App.ScreenWidth = metrics.WidthPixels;
App.ScreenHeight = metrics.HeightPixels;