Coder Social home page Coder Social logo

kunass2 / foregroundnotification Goto Github PK

View Code? Open in Web Editor NEW
46.0 7.0 19.0 6.85 MB

Present your custom iOS 10 notification when app is in foreground mode.

License: MIT License

Ruby 2.93% Swift 75.76% Objective-C 1.66% Shell 19.64%
notifications foreground-notification podfile cocoapods ios swift swift3

foregroundnotification's Introduction

ForegroundNotification

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

ForegroundNotification is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BSForegroundNotification"

If you used use_framework in your podfile just simply do:

import ForegroundNotification

for every file when you need to use it.

you may also use:

@import ForegroundNotification

within bridging header file and avoid to import framework for every needed file.

##Info

  • entirely written in latest Swift syntax. Works with iOS 8 and 9 and Xcode7.
  • to present local foreground notification, both alertTitle and alertBody cannot be nil
  • to present remote foreground notification, both title and body cannot be nil in alert dictionary. In case when alert is a string, that string cannot be empty.

##Usage

######Simply create your foreground notification object with on of three ways:

let notification = ForegroundNotification(userInfo: userInfo) //remote
let notification = ForegroundNotification(localNotification: localNotification) //local
let notification = ForegroundNotification(titleLabel: "title", subtitleLabel: "subtitle", categoryIdentifier: "category") //custom initializer

######Set a default static properties:

ForegroundNotification.timeToDismissNotification = 4
ForegroundNotification.systemSoundID: SystemSoundID = 1001

######Set delegate which conform to protocol BSForegroundNotificationDelegate:

Note that ForegroundNotificationDelegate inherits from UIApplicationsDelegate

notification.delegate = self

######Implement optional methods of ForegroundNotificationDelegate

@objc public protocol ForegroundNotificationDelegate: class, UIApplicationDelegate {

    optional func foregroundRemoteNotificationWasTouched(with userInfo: [AnyHashable: Any])
    optional func foregroundLocalNotificationWasTouched(with localNotification: UILocalNotification)
}

######Then present notification:

notification.presentNotification()

######If it is needed one of ForegroundNotificationDelegate's method is called':

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable: Any], completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable: Any], withResponseInfo responseInfo: [AnyHashable: Any], completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [AnyHashable: Any], completionHandler: () -> Void)

Author

Bartłomiej Semańczyk, [email protected]

License

BSForegroundNotification is available under the MIT license. See the LICENSE file for more info.

foregroundnotification's People

Contributors

dilizarov avatar heygul avatar kunass2 avatar thebehera 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

foregroundnotification's Issues

notification.presentNotification() not presenting notification?

In my AppDelegate I have the following code:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    let state = application.applicationState

    if state == .Active {
        let notification = BSForegroundNotification(userInfo: userInfo)
        notification.delegate = self
        notification.presentNotification()
    }
}

For some reason, the notification is not being presented. Is it not meant for use in AppDelegate?

Showing Lorem Ipsum when `alert` isn't a dictionary.

The didSet of BSForegroundNotificationView's userInfo isn't exhaustive in the way it fills its UILabel's texts.
When alert is a simple String value and there's no body, it will update the titleLabel, but leave the subtitleTextView showing a Lorem Ipsum message

Increase the size of the "send" button for TextInput actions

Problem
When attempting to "send" user inputted text for a notification uses .TextInput actions, it's too easy to accidentally dismiss the notification rather than triggering application(application:, handleActionWithIdentifier:, forRemoteNotification:, withResponseInfo: , completionHandler:
If the notification is accidentally closed, the user has lost all of his inputted text and there is no way to recover it... it's a waste of time for the user + the user will believe that it has worked properly. This is really the biggest issue here... I discovered this the hard way. It's essentially a false positive.

Solution
Increase the the size of the "send" button so that tapping anywhere near the "send" text will trigger the expected chain of events rather than closing the notification.

Trigger Action

How can i trigger when user tab the notification, and the button action?

Queue multiple notifications rather than displaying them simultaneously.

On screen notifications should be limited to 1 at a time. Currently they just pile on top of each other which is not ideal. Instead, notifications should be added to a queue, which would be responsible for presenting the next notification from the queue once the previous one has been dismissed. Doing this fixes:

  • Notifications piling up and becoming hard to read because of view transparency.
  • User being interrupted from his interaction with the first notification.
  • UIStatusBar hide/unhiding bug. Currently once the first notification disappears, the status bar is unhidden.... even if a new notification is already on screen.
  • Inconsistency from the way Apple displays push notifications (they use a queue).

Not working in Foreground

Is there a method to call when the app is in a foreground and is there a way for notifications not to show when the app is in use?

Swift 3.0

Are you planning on making this compatible with Swift 3.0?

Object-C

Hi, do u know if is a problem use this in a project object-c ?

Best

Install issue

Hi,

I have added "pod 'BSForegroundNotification'" in my podfile and tried to execute "pod update". Getting error

Analyzing dependencies
[!] Unable to satisfy the following requirements:

  • BSForegroundNotification required by Podfile

Thanks,
KSD

pod is still at v1.9.1

adding pod "BSForegroundNotification" to podfile retrieves older 1.9.1 not a newer 2.0 version.

can not handle localpushnotification

I have tried to use local BSForegroundNotification to get local push notification. But when I touched the notification, no reaction. I use this code:
_

func application (application: UIApplication, handleActionWithIdentifier identifier: String ?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void)

_
in my AppDelegate, but it still did not happen anything.
What should I do?
Thanks.

Can't open Firebase push notification

Hi there.

I am struggling with displaying push notifications sent from my Firebase console in my app. It obviously shows when my phone screen is locked, but I can't seem to get this working. I honestly have to say that I am also a bit confused, and I would really appreciate if any could help me with this.

This is some of my code in appDelegate.swift:

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        let token = FIRInstanceID.instanceID().token()
        FIRMessaging.messaging().appDidReceiveMessage(userInfo)

        print(token)
        print("MessageID : \(userInfo["gcm_message_id"])")
        print(userInfo)


    }

It's in here I have put the code for the foreground push notification as well. So it looks like this:

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        let token = FIRInstanceID.instanceID().token()
        FIRMessaging.messaging().appDidReceiveMessage(userInfo)

        print(token)
        print("MessageID : \(userInfo["gcm_message_id"])")
        print(userInfo)

         let notification = BSForegroundNotification(userInfo: userInfo)

        BSForegroundNotification.systemSoundID = 1004
        notification.delegate = self
        notification.presentNotification()
    }

However, this does not seem to work. Any ideas on how I would solve this?

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.