Coder Social home page Coder Social logo

square / superdelegate Goto Github PK

View Code? Open in Web Editor NEW
454.0 22.0 28.0 87 KB

SuperDelegate provides a clean application delegate interface and protects you from bugs in the application lifecycle

License: Apache License 2.0

Ruby 0.32% Swift 99.16% Objective-C 0.52%

superdelegate's Introduction

DEPRECATED

This library has been deprecated and is no longer under active development. The original README can be found in README_OLD, but we would recommend moving away from using this library in the future.

If you still find this project useful and are interested in taking over maintenance of this project, please feel free to file an issue requesting transfer of ownership.

superdelegate's People

Contributors

benjohnde avatar dfed avatar gfontenot avatar mikelikespie avatar nickentin avatar shawnwelch 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

superdelegate's Issues

SuperDelegate should not contain test helpers

I suggest to move the method testing_resetAllData() from Sources to Tests. Without having deep dived into that, I guess that we could also add this functionality via extension :).

Swift 4.2 support

Swift 4.2 introduced a bunch of churn around imported UIKit interfaces. The result is that SuperDelegate fails to build with Swift 4.2 entirely.

I'm happy to do the work to update the library for 4.2, but before I do: how have these updates been handled in the past. Do we want to maintain backwards compatibility, or do we want to bump the version number and only support 4.2+?

setup(mainWindow:) shouldn't set UIWindow's bounds on iOS9+

When setting UIWindow's bounds to UIScreen.main.bounds it breaks apps on iPads with iOS 9 and higher. This is caused because of the multitasking feature introduced in iOS 9. Setting those bound make the app appear under the status bar. Having just makeKeyAndVisible results in correct behavior.

[1.0] Adopt UIUserNotification* API from iOS 10 SDK

Today, SuperDelegate does not utilize new UIUserNotification API that redefines how developers:

  • Request user notification permissions
  • Receive user notifications (both local and remote)

To ensure that user notifications continue to work well on iOS 10, we need to adopt this API. The end goal is to provide a simple API for user notifications that works the same way on iOS 8, 9 and 10. Thankfully, SuperDelegate has already broken out concept of UserNotifications via the UserNotificationCapable protocol. In order to have a consistent API on iOS 8, 9, and 10, we'll need to define a new UserNotification struct that can be initialized with:

  • A UIUserNotification for iOS 10+
  • A [NSObject : AnyObject]? for iOS 8 and 9

We will also need to create a UserNotificationActionCapable that will likely subsume the LocalNotificationActionCapable and RemoteNotificationActionCapable protocols.

As we learn more about the UIUserNotification API, we'll put additional learnings here.

Optional protocol requirements

Any plans on using optional protocol requirements? Sometimes you only need one specific function to be invoked instead of all.

Of course, you can easily ignore the others. But wouldn't it be nicer to just use the necessary protocol requirements a specific use case demands?

App Delegate Life Cycle Protocol

Hi. We are in need of the following delegate calls for analytics as well as some core data handling:

Transitioning to the foreground:
- applicationDidBecomeActive(_:)

Transitioning to the background:
- applicationDidEnterBackground(_:)

Transitioning to the inactive state:
- applicationWillResignActive(_:) (Called when leaving the foreground state.)
- applicationWillEnterForeground(_:) (Called when transitioning out of the background state.)

Termination:
- applicationWillTerminate(_:) (Called only when the app is running. This method is not called if the app is suspended.)

Hence, I propose some sort of LifeCycleProtocol, maybe LifeCycleAware, in order to retrieve those delegate calls.

protocol LifeCycleAware {
  func transitionedToForeground()
  func transitionedToBackground()

  func transitioningToBackground()
  func transitioningToForeground()

  func terminatingApplication()
}

Cheers!

Should not need to re-request UserNotification permissions on every WillEnterForeground

We should be able just use currentUserNotificationSettings. Not re-requesting will reduce noise on the API, and more over currentUserNotificationSettings is known to be more reliable than the notification settings passed down into application(_:didRegister:).

Our re-request is a holdover from iOS 7, e.g the days before currentUserNotificationSettings existed.

Emphasize UIApplicationDelegate protocol requirements

Adjust sample project to emphasize UIApplicationDelegate protocol requirements.

In the current example project window is defined as:

  let window = UIWindow()

If I am using some libraries like SVProgressHUD which access the current UIWindow via the following selector UIApplication.shared.delegate?.window they all crash as this invocation returns nil.

Hence, I propose to update the sample project to meet those protocol requirements.

Build fails when integrating through Cocoapods

As mentioned in the title, building the app fails in file SuperDelegate+LocalNotifications.swift on line 22.

Error: No such module 'UserNotifications'.

My Podfile:

platform :ios, '8.0'

target 'NewProject' do
    use_frameworks!
    pod 'SuperDelegate'
end

Cocoapods version 1.0.1

RemoteNotification should search for values in "aps" dictionary instead of top level.

I'm not really sure about this, as I'm new to using remote notifications.
But reading the documentation gives me the impression that the userInfo dictionary has an aps dictionary inside with the values.

So the RemoteNotification's init should actually look more like this:

public init?(remoteNotification: [NSObject : AnyObject]?) {
    guard let remoteNotification = remoteNotification as? [String : AnyObject] else {
        return nil
    }

    let apsKey = "aps"
    let aps = remoteNotification[apsKey] as? [String : AnyObject]

    alert = aps.flatMap(Alert.init(remoteNotification:))
    badge = aps?[badgeKey] as? Int
    sound = aps?[soundKey] as? String
    contentAvailable = aps?[contentAvailableKey] != nil
    categoryIdentifier = aps?[categoryKey] as? String
    remoteNotificationDictionary = remoteNotification

    var customFields = remoteNotification
    customFields.removeValueForKey(apsKey)

    userInfo = customFields
}

At least that seems to work for me, what do you think?

Add LaunchItem for unknown launch options

Currently, when launch options contains a set of parameters we don't recognize, we just strip the options and launch with .none, at which point there is no way to recover the lost options. Instead, we should add a LaunchItem.unknown(options: [UIApplicationLaunchOptionsKey : Any]) case and keep .none strictly for when launch options is nil or empty.

Add optional method that has unedited launchOptions?

Unfortunately there's some SDK's that require the launchOptions directly. Maybe there could be an addition to have an optional protocol method that has these unedited launchOptions. I could not find any other built in work-around for this issue.

Tapping on a notification in Notification Center while app in foreground but inactive doesn't return .UserTappedToBringAppToForeground

If a notification is received when the app is not in foreground, the app is then launched, notification center is opened and a notification is tapped, the notificationOrigin is marked as .DeliveredWhileInForground.

I noticed that in that case, the following is true:
applicationIsInForeground && application.applicationState == .Inactive

I propose that we look for that case and return .UserTappedToBringAppToForeground instead.
Something like this:

    let notificationOrigin: UserNotificationOrigin
    if applicationIsInForeground {
        notificationOrigin = application.applicationState == .Inactive
            ? .UserTappedToBringAppToForeground
            : .DeliveredWhileInForground
    } else if application.applicationState == .Background && remoteNotification.contentAvailable {
        notificationOrigin = .DeliveredWhileInBackground
    } else {
        notificationOrigin = .UserTappedToBringAppToForeground
    }

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.