Skip to content

Commit f4ae4a4

Browse files
re-enable style script for messaging (#4858)
1 parent 1dad9c5 commit f4ae4a4

File tree

82 files changed

+1661
-1842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1661
-1842
lines changed

Example/Messaging/App/iOS/NotificationService/NotificationService.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,29 @@
1818

1919
@interface NotificationService ()
2020

21-
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
22-
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
21+
@property(nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
22+
@property(nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
2323

2424
@end
2525

2626
@implementation NotificationService
2727

28-
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
29-
self.contentHandler = contentHandler;
30-
self.bestAttemptContent = [request.content mutableCopy];
28+
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request
29+
withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
30+
self.contentHandler = contentHandler;
31+
self.bestAttemptContent = [request.content mutableCopy];
3132

32-
// Modify the notification content here...
33-
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
33+
// Modify the notification content here...
34+
self.bestAttemptContent.title =
35+
[NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
3436

35-
self.contentHandler(self.bestAttemptContent);
37+
self.contentHandler(self.bestAttemptContent);
3638
}
3739

3840
- (void)serviceExtensionTimeWillExpire {
39-
// Called just before the extension will be terminated by the system.
40-
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
41+
// Called just before the extension will be terminated by the system.
42+
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the
43+
// original push payload will be used.
4144
self.contentHandler(self.bestAttemptContent);
4245
}
4346

Example/Messaging/App/tvOS/AppDelegate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1818

19-
@property (strong, nonatomic) UIWindow *window;
20-
19+
@property(strong, nonatomic) UIWindow *window;
2120

2221
@end
23-

Example/Messaging/App/tvOS/AppDelegate.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,40 @@ @interface AppDelegate ()
2020

2121
@implementation AppDelegate
2222

23-
24-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
25-
// Override point for customization after application launch.
26-
return YES;
23+
- (BOOL)application:(UIApplication *)application
24+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
25+
// Override point for customization after application launch.
26+
return YES;
2727
}
2828

29-
3029
- (void)applicationWillResignActive:(UIApplication *)application {
31-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
32-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
30+
// Sent when the application is about to move from active to inactive state. This can occur for
31+
// certain types of temporary interruptions (such as an incoming phone call or SMS message) or
32+
// when the user quits the application and it begins the transition to the background state. Use
33+
// this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
34+
// Games should use this method to pause the game.
3335
}
3436

35-
3637
- (void)applicationDidEnterBackground:(UIApplication *)application {
37-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
38-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
38+
// Use this method to release shared resources, save user data, invalidate timers, and store
39+
// enough application state information to restore your application to its current state in case
40+
// it is terminated later. If your application supports background execution, this method is
41+
// called instead of applicationWillTerminate: when the user quits.
3942
}
4043

41-
4244
- (void)applicationWillEnterForeground:(UIApplication *)application {
43-
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
45+
// Called as part of the transition from the background to the active state; here you can undo
46+
// many of the changes made on entering the background.
4447
}
4548

46-
4749
- (void)applicationDidBecomeActive:(UIApplication *)application {
48-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
50+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If
51+
// the application was previously in the background, optionally refresh the user interface.
4952
}
5053

51-
5254
- (void)applicationWillTerminate:(UIApplication *)application {
53-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
55+
// Called when the application is about to terminate. Save data if appropriate. See also
56+
// applicationDidEnterBackground:.
5457
}
5558

56-
5759
@end

Example/Messaging/App/tvOS/ViewController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
@interface ViewController : UIViewController
1818

19-
2019
@end
21-

Example/Messaging/App/tvOS/ViewController.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ @interface ViewController ()
2121
@implementation ViewController
2222

2323
- (void)viewDidLoad {
24-
[super viewDidLoad];
25-
// Do any additional setup after loading the view, typically from a nib.
24+
[super viewDidLoad];
25+
// Do any additional setup after loading the view, typically from a nib.
2626
}
2727

28-
2928
- (void)didReceiveMemoryWarning {
30-
[super didReceiveMemoryWarning];
31-
// Dispose of any resources that can be recreated.
29+
[super didReceiveMemoryWarning];
30+
// Dispose of any resources that can be recreated.
3231
}
3332

34-
3533
@end

Example/Messaging/App/tvOS/main.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#import <UIKit/UIKit.h>
1616
#import "AppDelegate.h"
1717

18-
int main(int argc, char * argv[]) {
19-
@autoreleasepool {
20-
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
21-
}
18+
int main(int argc, char* argv[]) {
19+
@autoreleasepool {
20+
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
21+
}
2222
}

Example/Messaging/Sample/iOS/AppDelegate.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import UserNotifications
2121

2222
@UIApplicationMain
2323
class AppDelegate: UIResponder, UIApplicationDelegate {
24-
2524
var window: UIWindow?
2625

2726
static let isWithinUnitTest: Bool = {
@@ -53,7 +52,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5352
Messaging.messaging().delegate = self
5453
Messaging.messaging().shouldEstablishDirectChannel = true
5554
// Just for logging to the console when we establish/tear down our socket connection.
56-
listenForDirectChannelStateChanges();
55+
listenForDirectChannelStateChanges()
5756

5857
NotificationsController.configure()
5958

@@ -74,8 +73,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7473
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
7574
print("APNS Token: \(deviceToken.hexByteString)")
7675
NotificationCenter.default.post(name: APNSTokenReceivedNotification, object: nil)
77-
if #available(iOS 8.0, *) {
78-
} else {
76+
if #available(iOS 8.0, *) {} else {
7977
// On iOS 7, receiving a device token also means our user notifications were granted, so fire
8078
// the notification to update our user notifications UI
8179
NotificationCenter.default.post(name: UserNotificationsChangedNotification, object: nil)
@@ -87,7 +85,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8785
NotificationCenter.default.post(name: UserNotificationsChangedNotification, object: nil)
8886
}
8987

90-
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
88+
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
9189
print("application:didReceiveRemoteNotification:fetchCompletionHandler: called, with notification:")
9290
print("\(userInfo.jsonString ?? "{}")")
9391
completionHandler(.newData)
@@ -96,8 +94,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
9694
func applicationDidBecomeActive(_ application: UIApplication) {
9795
// If the app didn't start property due to an invalid GoogleService-Info.plist file, show an
9896
// alert to the developer.
99-
if !SampleAppUtilities.appContainsRealServiceInfoPlist() &&
100-
!AppDelegate.hasPresentedInvalidServiceInfoPlistAlert {
97+
if !SampleAppUtilities.appContainsRealServiceInfoPlist(),
98+
!AppDelegate.hasPresentedInvalidServiceInfoPlistAlert {
10199
if let vc = window?.rootViewController {
102100
SampleAppUtilities.presentAlertForInvalidServiceInfoPlistFrom(vc)
103101
AppDelegate.hasPresentedInvalidServiceInfoPlistAlert = true
@@ -132,20 +130,20 @@ extension AppDelegate: MessagingDelegate {
132130
}
133131

134132
extension AppDelegate {
135-
func listenForDirectChannelStateChanges() {
136-
NotificationCenter.default.addObserver(self, selector: #selector(onMessagingDirectChannelStateChanged(_:)), name: .MessagingConnectionStateChanged, object: nil)
137-
}
133+
func listenForDirectChannelStateChanges() {
134+
NotificationCenter.default.addObserver(self, selector: #selector(onMessagingDirectChannelStateChanged(_:)), name: .MessagingConnectionStateChanged, object: nil)
135+
}
138136

139-
func onMessagingDirectChannelStateChanged(_ notification: Notification) {
140-
print("FCM Direct Channel Established: \(Messaging.messaging().isDirectChannelEstablished)")
141-
}
137+
func onMessagingDirectChannelStateChanged(_ notification: Notification) {
138+
print("FCM Direct Channel Established: \(Messaging.messaging().isDirectChannelEstablished)")
139+
}
142140
}
143141

144142
extension Dictionary {
145143
/// Utility method for printing Dictionaries as pretty-printed JSON.
146144
var jsonString: String? {
147145
if let jsonData = try? JSONSerialization.data(withJSONObject: self, options: [.prettyPrinted]),
148-
let jsonString = String(data: jsonData, encoding: .utf8) {
146+
let jsonString = String(data: jsonData, encoding: .utf8) {
149147
return jsonString
150148
}
151149
return nil

Example/Messaging/Sample/iOS/Data+MessagingExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ extension Data {
2020
// Print Data as a string of bytes in hex, such as the common representation of APNs device tokens
2121
// See: http://stackoverflow.com/a/40031342/9849
2222
var hexByteString: String {
23-
return self.map { String(format: "%02.2hhx", $0) }.joined()
23+
return map { String(format: "%02.2hhx", $0) }.joined()
2424
}
2525
}

Example/Messaging/Sample/iOS/MessagingViewController.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import UIKit
1919
import FirebaseMessaging
2020

2121
enum Row: String {
22-
case apnsToken = "apnsToken"
23-
case apnsStatus = "apnsStatus"
24-
case requestAPNSPermissions = "requestAPNSPermissions"
25-
case fcmToken = "fcmToken"
22+
case apnsToken
23+
case apnsStatus
24+
case requestAPNSPermissions
25+
case fcmToken
2626
}
2727

2828
enum PermissionsButtonTitle: String {
@@ -33,7 +33,6 @@ enum PermissionsButtonTitle: String {
3333
}
3434

3535
class MessagingViewController: UIViewController {
36-
3736
let tableView: UITableView
3837

3938
var sections = [[Row]]()
@@ -58,7 +57,7 @@ class MessagingViewController: UIViewController {
5857
override func loadView() {
5958
super.loadView()
6059
view = UIView(frame: CGRect.zero)
61-
view.addSubview(self.tableView)
60+
view.addSubview(tableView)
6261
// Ensure that the tableView always is the size of the view
6362
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
6463
}
@@ -67,7 +66,7 @@ class MessagingViewController: UIViewController {
6766
super.viewDidLoad()
6867
let center = NotificationCenter.default
6968
center.addObserver(self,
70-
selector: #selector(onAPNSTokenReceived) ,
69+
selector: #selector(onAPNSTokenReceived),
7170
name: APNSTokenReceivedNotification,
7271
object: nil)
7372
center.addObserver(self,
@@ -88,8 +87,8 @@ class MessagingViewController: UIViewController {
8887
// Reload the appropriate cells
8988
updateAllowedNotificationTypes {
9089
if let tokenPath = self.indexPathFor(.apnsToken),
91-
let statusPath = self.indexPathFor(.apnsStatus),
92-
let requestPath = self.indexPathFor(.requestAPNSPermissions) {
90+
let statusPath = self.indexPathFor(.apnsStatus),
91+
let requestPath = self.indexPathFor(.requestAPNSPermissions) {
9392
self.updateIndexPaths(indexPaths: [tokenPath, statusPath, requestPath])
9493
}
9594
}
@@ -104,7 +103,7 @@ class MessagingViewController: UIViewController {
104103
func onUserNotificationSettingsChanged() {
105104
updateAllowedNotificationTypes {
106105
if let statusPath = self.indexPathFor(.apnsStatus),
107-
let requestPath = self.indexPathFor(.requestAPNSPermissions) {
106+
let requestPath = self.indexPathFor(.requestAPNSPermissions) {
108107
self.updateIndexPaths(indexPaths: [statusPath, requestPath])
109108
}
110109
}
@@ -117,7 +116,7 @@ class MessagingViewController: UIViewController {
117116
}
118117

119118
fileprivate func updateAllowedNotificationTypes(_ completion: (() -> Void)?) {
120-
NotificationsController.shared.getAllowedNotificationTypes { (types) in
119+
NotificationsController.shared.getAllowedNotificationTypes { types in
121120
self.allowedNotificationTypes = types
122121
self.updateRequestAPNSButton()
123122
completion?()
@@ -137,14 +136,15 @@ class MessagingViewController: UIViewController {
137136
}
138137

139138
requestPermissionsButton.isEnabled =
140-
(allowedTypes.count == 1 && allowedTypes.first! == .silent)
139+
(allowedTypes.count == 1 && allowedTypes.first! == .silent)
141140

142141
let title: PermissionsButtonTitle =
143-
(requestPermissionsButton.isEnabled ? .requestPermissions : .alreadyRequested)
142+
(requestPermissionsButton.isEnabled ? .requestPermissions : .alreadyRequested)
144143
requestPermissionsButton.setTitle(title.rawValue, for: .normal)
145144
}
146145

147146
// MARK: UI (Cells and Buttons) Defined as lazy properties
147+
148148
lazy var apnsTableCell: UITableViewCell = {
149149
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: Row.apnsToken.rawValue)
150150
cell.textLabel?.numberOfLines = 0
@@ -191,6 +191,7 @@ class MessagingViewController: UIViewController {
191191
}
192192

193193
// MARK: - Configuring the table view and cells with information
194+
194195
extension MessagingViewController {
195196
func resetTableContents() {
196197
sections.removeAll()
@@ -205,7 +206,6 @@ extension MessagingViewController {
205206
let fcmSection: [Row] = [.fcmToken]
206207
sections.append(fcmSection)
207208
sectionHeaderTitles.append("FCM Token")
208-
209209
}
210210

211211
func indexPathFor(_ rowId: Row) -> IndexPath? {
@@ -240,7 +240,7 @@ extension MessagingViewController {
240240

241241
func configureCellWithAPNSStatus(_ cell: UITableViewCell) {
242242
if let allowedNotificationTypes = allowedNotificationTypes {
243-
let displayableTypes: [String] = allowedNotificationTypes.map { return $0.rawValue }
243+
let displayableTypes: [String] = allowedNotificationTypes.map { $0.rawValue }
244244
cell.detailTextLabel?.text = displayableTypes.joined(separator: ", ")
245245
} else {
246246
cell.detailTextLabel?.text = "Retrieving..."
@@ -259,6 +259,7 @@ extension MessagingViewController {
259259
}
260260

261261
// MARK: - UITableViewDataSource
262+
262263
extension MessagingViewController: UITableViewDataSource {
263264
func numberOfSections(in tableView: UITableView) -> Int {
264265
return sections.count
@@ -295,6 +296,7 @@ extension MessagingViewController: UITableViewDataSource {
295296
}
296297

297298
// MARK: - UITableViewDelegate
299+
298300
extension MessagingViewController: UITableViewDelegate {
299301
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
300302
tableView.deselectRow(at: indexPath, animated: true)
@@ -315,18 +317,19 @@ extension MessagingViewController: UITableViewDelegate {
315317
}
316318

317319
// MARK: - UI Controls
320+
318321
extension MessagingViewController {
319322
func onRequestUserNotificationsButtonTapped(sender: UIButton) {
320323
NotificationsController.shared.registerForUserFacingNotificationsFor(UIApplication.shared)
321324
}
322325
}
323326

324327
// MARK: - Activity View Controller
328+
325329
extension MessagingViewController {
326330
func showActivityViewControllerFor(sharedItem: Any) {
327331
let activityViewController = UIActivityViewController(activityItems: [sharedItem],
328332
applicationActivities: nil)
329333
present(activityViewController, animated: true, completion: nil)
330334
}
331335
}
332-

0 commit comments

Comments
 (0)