Skip to content

Instantly share code, notes, and snippets.

# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md
# can also be listed using the `fastlane actions` command
# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`
# If you want to automatically update fastlane if a new version is available:
# update_fastlane
@suraphanL
suraphanL / Podfile
Last active September 23, 2016 16:19
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!
target 'BuildConfigurations' do
pod 'SVProgressHUD', '~> 1.0'
pod 'SwiftyJSON', '~> 2.3'
pod 'Socket.IO-Client-Swift', :git => 'https://github.com/socketio/socket.io-client-swift', :branch => 'swift2.3'
end
source "https://rubygems.org"
gem 'cocoapods', '0.39.0'
gem 'fastlane'
{
"aps": {
"alert": "Remotely pushing.",
"mutable-content": 1
},
"attachement-url": "https://gnosticbent.files.wordpress.com/2014/03/dude-wtf-wtf-foundation.jpg"
}
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
func failEarly() {
print("fail")
contentHandler(request.content)
}
guard let content = (request.content.mutableCopy() as? UNMutableNotificationContent) else {
return failEarly()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
print(granted)
print(error)
}
UIApplication.shared.registerForRemoteNotifications()
return true
}
let gameScoreIdentifier = "game1.score.identifier"
let gameScoreRequest = UNNotificationRequest(identifier: gameScoreIdentifier,
content: scoreContent,
trigger: trigger)
UNUserNotificationCenter.current().add(gameScoreRequest) { (error) in // ... }
// Wrong game score was published
UNUserNotificationCenter.current()
.removeDeliveredNotifications(withIdentifiers: [gameScoreIdentifier])
public protocol UNUserNotificationCenterDelegate : NSObjectProtocol {
// The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
@available(iOS 10.0, *)
optional public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void)
// The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from
let requestIdentifier = "sampleRequest"
let request = UNNotificationRequest(identifier: requestIdentifier,
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in // ... }
// Notification requests can be scheduled to notify the user via time and location.
// See UNNotificationTrigger for more information.
// Calling -addNotificationRequest: will replace an existing notification request with the same identifier.
//In 2 minutes from now
UNTimeIntervalNotificationTrigger(timeInterval: 120,
repeats: false)
//Repeat every hour starting now
UNTimeIntervalNotificationTrigger(timeInterval: 3600,
repeats: true)
//Now
UNTimeIntervalNotificationTrigger(timeInterval: 0,