Git Product home page Git Product logo

jpsimulatorhacks's Introduction

Build Status Carthage compatible

JPSimulatorHacks

Description

Hack the Simulator in your tests (grant access to photos, contacts, calendar ...).

Did you ever have the problem that your code was wrapping the AddressBook, the EventKit or the ALAssetsLibrary APIs? Running tests can be annoying then. There's this UIAlertView asking the user to grant access to the contacts and photos, which blocks and breaks your tests. Using JPSimulatorHacks you can easily grant this access before running your tests.

If you encounter any problems, please check out the caveats documented below.

Installation

Install JPSimulatorHacks with CocoaPods

pod 'JPSimulatorHacks'

Or, install via Carthage

github "plu/JPSimulatorHacks"

Usage

AddressBook

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToAddressBook];
}

@end

This will grant access to the addressbook for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToAddressBookForBundleIdentifier:(NSString *)bundleIdentifier;

Calendar

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToCalendar];
}

@end

This will grant access to the calendar for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToCalendarForBundleIdentifier:(NSString *)bundleIdentifier;

HomeKit

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToHomeKit];
}

@end

This will grant access to HomeKit for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL) grantAccessToHomeKitForBundleIdentifier:(NSString *)bundleIdentifier;

Photos

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToPhotos];
}

@end

This will grant access to the photos library for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToPhotosForBundleIdentifier:(NSString *)bundleIdentifier;

You can also add some test images from a given URL. The method will block until the Asset has been stored. This is helpful so your tests will only start after the Asset is available.

[JPSimulatorHacks grantAccessToPhotos];
NSURL *assetURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/plu/JPSimulatorHacks/master/Data/test.png"];
ALAsset *asset = [JPSimulatorHacks addAssetWithURL:assetURL];

Contacts (iOS 9)

This will grant permission for the new Contacts Framework which comes with iOS 9.

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToContacts];
}

@end

Timeout

By default it tries to write the necessary entries to the TCC.db within 15 seconds. If that's not enough time, it just gives up and returns NO from the methods. If for any reason that is not enough time, you can change this default timeout via:

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks setTimeout:30.0f];
}

Caveats

  • JPSimulatorHacks only works if unit test suite is run against real application target: Its Host Application is not set to None! See also: http://stackoverflow.com/a/28135995/598057
  • When using Xcode bots, sometimes the tests run into an timeout.
  • The keyboard helpers have been removed in 1.3.0

License (MIT)

Copyright (C) 2014 Johannes Plunien

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jpsimulatorhacks's People

Contributors

abdullahselek avatar anefkens avatar dkhamsing avatar plu avatar readmecritic avatar stanislaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpsimulatorhacks's Issues

Unable to install via Carthage

Hi, I'm trying to include this in my project via carthage and I get the following error in my terminal:

$ carthage update --verbose
*** Fetching JPSimulatorHacks
*** Checking out JPSimulatorHacks at "1.4.1"
*** Skipped building JPSimulatorHacks due to the error:
Dependency "JPSimulatorHacks" has no shared framework schemes

If you believe this to be an error, please file an issue with the maintainers at Optional("https://github.com/plu/JPSimulatorHacks/issues/new")

I tried both the git and github methods of adding to the cartfile

#git "[email protected]:plu/JPSimulatorHacks.git"
github "plu/JPSimulatorHacks"

Any ideas?

Use this in apps on phone

Hi,
Is it possible to do the same thing with app that is installed on an iphone? Not just the simulator?

#import "sqlite3.h" in JPSimulatorHacksDB.h causes build failure in swift

When I added the JPSimulatorHacks pod to my swift project and added the #import <JPSimulatorHacks/JPSimulatorHacks.h> line to my bridging header, building failed with the error message:

(...)/Pods/JPSimulatorHacks/JPSimulatorHacks/JPSimulatorHacksDB.h:28:9: Include of non-modular header inside framework module 'JPSimulatorHacks.JPSimulatorHacksDB'

Looking on stackoverflow, I found the following http://stackoverflow.com/a/24728646/5215824 and moved #import "sqlite3.h" from JPSimulatorHacksDB.h to JPSimulatorHacksDB.m. That solved the issue and the library works like a charm...

Is there any need for the sqlite import in the public header file?

Notification permission

An excellent repo!
Was about to start a similar repo for detox when I found this one. Cool stuff!

One thing that seems not be stored in TCC.db is notification permissions. I am researching where this might be stored (a naive grep didn’t turn out anything so far). I will update here as my research goes. If anyone has an idea where it might be stored, please share.

If I find a solution I will submit a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.