Skip to content

Commit ac9903c

Browse files
elijahverdoornhawkrives
authored andcommitted
Add iOS notifications (#161)
* Remove ride-along change Didn't intend for that to be in here, was just faster to make another commit than to revert. * Use relative paths Xcode used absolute paths. I want to use relative paths. I am smarter than Xcode. * Make Travis work with Cocoapods (#164) * Change the test command to use the workspace file * switch to xcodebuild * Revert "switch to xcodebuild" fc5fa3e * switch to just building iOS * Add iOS notifications Using Cocoapods to add the code driving the OneSignal service for the notificaitons. The backend is registering the simulator that I'm using for iOS testing, but since simulators cannot get notificaitons I haven't seen the end-to-end process work yet. I'll be able to do that within the day and will make an update if it's not working as expected. * missed a thing while rebasing
1 parent 1881549 commit ac9903c

37 files changed

+1657
-30
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ script:
144144
- if [[ "$TEST_TYPE" == "js" ]]; then npm run test:js; fi
145145

146146
# iOS-only tests - building and specs
147-
- if [[ "$TEST_TYPE" == "ios" ]]; then npm run test:ios; fi
147+
- if [[ "$TEST_TYPE" == "ios" ]]; then npm run build:ios; fi
148148

149149
# android-only tests - building and specs
150150
- if [[ "$TEST_TYPE" == "android" ]]; then npm run build:android:unix; fi

index.ios.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
import {AppRegistry} from 'react-native'
22
import App from './app'
3+
import OneSignal from 'react-native-onesignal'
34
AppRegistry.registerComponent('AllAboutOlaf', () => App)
5+
6+
let pendingNotifications = [];
7+
// var _navigator; // If applicable, declare a variable for accessing your navigator object to handle payload.
8+
// function handleNotification (notification) { // If you want to handle the notifiaction with a payload.
9+
// _navigator.to('main.post', notification.data.title, {
10+
// article: {
11+
// title: notification.data.title,
12+
// link: notification.data.url,
13+
// action: notification.data.actionSelected
14+
// }
15+
//});
16+
// }
17+
18+
OneSignal.configure({
19+
onIdsAvailable: function(device) {
20+
console.log('UserId = ', device.userId);
21+
console.log('PushToken = ', device.pushToken);
22+
},
23+
onNotificationOpened: function(message, data, isActive) {
24+
var notification = {message: message, data: data, isActive: isActive};
25+
console.log('NOTIFICATION OPENED: ', notification);
26+
//if (!_navigator) { // Check if there is a navigator object. If not, waiting with the notification.
27+
// console.log('Navigator is null, adding notification to pending list...');
28+
pendingNotifications.push(notification);
29+
// return;
30+
// }
31+
handleNotification(notification);
32+
}
33+
})

ios/AllAboutOlaf.xcodeproj/project.pbxproj

Lines changed: 180 additions & 26 deletions
Large diffs are not rendered by default.

ios/AllAboutOlaf.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/AllAboutOlaf/AppDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#import <UIKit/UIKit.h>
1111

12+
#import <RCTOneSignal.h>
13+
1214
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1315

1416
@property (nonatomic, strong) UIWindow *window;
1517

18+
@property (strong, nonatomic) RCTOneSignal* oneSignal;
19+
1620
@end

ios/AllAboutOlaf/AppDelegate.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#import "RCTBundleURLProvider.h"
1313
#import "RCTRootView.h"
1414

15+
#import "RCTOneSignal.h"
16+
1517
@implementation AppDelegate
18+
@synthesize oneSignal = _oneSignal;
1619

1720
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1821
{
@@ -32,7 +35,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3235
rootViewController.view = rootView;
3336
self.window.rootViewController = rootViewController;
3437
[self.window makeKeyAndVisible];
38+
39+
self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
40+
appId:@"aa46a500-ab1c-4127-b9ff-e7373da3ce35"];
41+
3542
return YES;
3643
}
3744

45+
// Required for the notification event.
46+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
47+
[RCTOneSignal didReceiveRemoteNotification:notification];
48+
}
49+
3850
@end

ios/AllAboutOlaf/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
<string>Octicons.ttf</string>
102102
<string>Zocial.ttf</string>
103103
</array>
104+
<key>UIBackgroundModes</key>
105+
<array>
106+
<string>remote-notification</string>
107+
</array>
104108
<key>UIRequiredDeviceCapabilities</key>
105109
<array>
106110
<string>armv7</string>

ios/Podfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
target 'AllAboutOlaf' do
5+
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
6+
# use_frameworks!
7+
8+
# Pods for AllAboutOlaf
9+
pod 'OneSignal', '~> 1.13.2'
10+
11+
target 'AllAboutOlafTests' do
12+
inherit! :search_paths
13+
# Pods for testing
14+
end
15+
16+
end

ios/Podfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PODS:
2+
- OneSignal (1.13.3)
3+
4+
DEPENDENCIES:
5+
- OneSignal (~> 1.13.2)
6+
7+
SPEC CHECKSUMS:
8+
OneSignal: 434facae3389cb0d4d3fc57b9a6cf66db685205e
9+
10+
PODFILE CHECKSUM: 882acffa867f607ca76f374ff4d76e76f3dfd8c4
11+
12+
COCOAPODS: 1.0.1

ios/Pods/Headers/Public/OneSignal/OneSignal/GameThrive.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)