Skip to content

Commit 65db39f

Browse files
author
Joseph Kalash
committed
- Allow launch of inAppAlerts on iOS10.
- Added NotificationServiceExtension & NotificationContentExtension to the example projects. - Swift example upgraded to Swift 3.0.
1 parent 85c7380 commit 65db39f

File tree

26 files changed

+1064
-298
lines changed

26 files changed

+1064
-298
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: objective-c
2-
osx_image: xcode7.3
2+
osx_image: xcode8
33
xcode_project: OneSignal.xcodeproj
44
# xcode_workspace: <WORKSPACE_PLACEHOLDER>
55
xcode_scheme: OneSignal-Dynamic
6-
xcode_sdk: iphonesimulator9.3
6+
xcode_sdk: iphonesimulator10.0
77
env:
88
global:
99
- FRAMEWORK_NAME=OneSignal
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A320" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--Notification View Controller-->
10+
<scene sceneID="cwh-vc-ff4">
11+
<objects>
12+
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" sceneMemberID="viewController">
13+
<layoutGuides>
14+
<viewControllerLayoutGuide type="top" id="Ft6-oW-KC0"/>
15+
<viewControllerLayoutGuide type="bottom" id="FKl-LY-JtV"/>
16+
</layoutGuides>
17+
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
18+
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
19+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<subviews>
21+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello OneSignal" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="GcN-lo-r42">
22+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
23+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
24+
<nil key="highlightedColor"/>
25+
</label>
26+
</subviews>
27+
<color key="backgroundColor" red="0.45882353186607361" green="0.74901962280273438" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
28+
<constraints>
29+
<constraint firstItem="FKl-LY-JtV" firstAttribute="top" secondItem="GcN-lo-r42" secondAttribute="bottom" constant="8" symbolic="YES" id="0Q0-KW-PJ6"/>
30+
<constraint firstItem="GcN-lo-r42" firstAttribute="leading" secondItem="S3S-Oj-5AN" secondAttribute="leading" constant="20" symbolic="YES" id="6Vq-gs-PHe"/>
31+
<constraint firstAttribute="trailing" secondItem="GcN-lo-r42" secondAttribute="trailing" constant="20" symbolic="YES" id="L8K-9R-egU"/>
32+
<constraint firstItem="GcN-lo-r42" firstAttribute="top" secondItem="Ft6-oW-KC0" secondAttribute="bottom" constant="8" symbolic="YES" id="mYS-Cv-VNx"/>
33+
</constraints>
34+
</view>
35+
<extendedEdge key="edgesForExtendedLayout"/>
36+
<nil key="simulatedStatusBarMetrics"/>
37+
<nil key="simulatedTopBarMetrics"/>
38+
<nil key="simulatedBottomBarMetrics"/>
39+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
40+
<size key="freeformSize" width="320" height="37"/>
41+
<connections>
42+
<outlet property="label" destination="GcN-lo-r42" id="lpW-cU-7IG"/>
43+
</connections>
44+
</viewController>
45+
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
46+
</objects>
47+
<point key="canvasLocation" x="-78" y="62"/>
48+
</scene>
49+
</scenes>
50+
</document>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>OSContentExension</string>
9+
<key>CFBundleExecutable</key>
10+
<string>$(EXECUTABLE_NAME)</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>XPC!</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>NSExtension</key>
24+
<dict>
25+
<key>NSExtensionAttributes</key>
26+
<dict>
27+
<key>UNNotificationExtensionCategory</key>
28+
<string>myOSContentCategory</string>
29+
<key>UNNotificationExtensionInitialContentSizeRatio</key>
30+
<real>1</real>
31+
</dict>
32+
<key>NSExtensionMainStoryboard</key>
33+
<string>MainInterface</string>
34+
<key>NSExtensionPointIdentifier</key>
35+
<string>com.apple.usernotifications.content-extension</string>
36+
</dict>
37+
</dict>
38+
</plist>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// NotificationViewController.h
3+
// OSContentExension
4+
//
5+
// Created by Joseph Kalash on 9/12/16.
6+
// Copyright © 2016 OneSignal. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface NotificationViewController : UIViewController
12+
13+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// NotificationViewController.m
3+
// OSContentExension
4+
//
5+
// Created by Joseph Kalash on 9/12/16.
6+
// Copyright © 2016 OneSignal. All rights reserved.
7+
//
8+
9+
#import "NotificationViewController.h"
10+
#import <UserNotifications/UserNotifications.h>
11+
#import <UserNotificationsUI/UserNotificationsUI.h>
12+
13+
@interface NotificationViewController () <UNNotificationContentExtension>
14+
15+
@property IBOutlet UILabel *label;
16+
17+
@end
18+
19+
@implementation NotificationViewController
20+
21+
- (void)viewDidLoad {
22+
[super viewDidLoad];
23+
24+
}
25+
26+
- (void)didReceiveNotification:(UNNotification *)notification {
27+
self.label.text = notification.request.content.body;
28+
}
29+
30+
@end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>OSServiceExtension</string>
9+
<key>CFBundleExecutable</key>
10+
<string>$(EXECUTABLE_NAME)</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>XPC!</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>NSExtension</key>
24+
<dict>
25+
<key>NSExtensionPointIdentifier</key>
26+
<string>com.apple.usernotifications.service</string>
27+
<key>NSExtensionPrincipalClass</key>
28+
<string>NotificationService</string>
29+
</dict>
30+
</dict>
31+
</plist>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// NotificationService.h
3+
// OSServiceExtension
4+
//
5+
// Created by Joseph Kalash on 9/12/16.
6+
// Copyright © 2016 OneSignal. All rights reserved.
7+
//
8+
9+
#import <UserNotifications/UserNotifications.h>
10+
11+
@interface NotificationService : UNNotificationServiceExtension
12+
13+
@end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// NotificationService.m
3+
// OSServiceExtension
4+
//
5+
// Created by Joseph Kalash on 9/12/16.
6+
// Copyright © 2016 OneSignal. All rights reserved.
7+
//
8+
9+
#import "NotificationService.h"
10+
11+
@interface NotificationService ()
12+
13+
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
14+
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
15+
16+
@end
17+
18+
@implementation NotificationService
19+
20+
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
21+
22+
self.contentHandler = contentHandler;
23+
self.bestAttemptContent = [request.content mutableCopy];
24+
25+
// Modify the notification content here...
26+
self.bestAttemptContent.title = [NSString stringWithFormat:@"[Modified-thorugh-OneSignal] %@", self.bestAttemptContent.title];
27+
28+
self.contentHandler(self.bestAttemptContent);
29+
}
30+
31+
- (void)serviceExtensionTimeWillExpire {
32+
// Called just before the extension will be terminated by the system.
33+
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
34+
self.contentHandler(self.bestAttemptContent);
35+
}
36+
37+
@end

0 commit comments

Comments
 (0)