Skip to content

Commit

Permalink
feat(ios): Add push notification capabilities & small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Nov 6, 2018
1 parent 747ed41 commit f38b054
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 19 deletions.
7 changes: 6 additions & 1 deletion client/react-native/common/components/App.js
Expand Up @@ -23,7 +23,12 @@ export default class App extends PureComponent {
async componentDidMount () {
try {
await CoreModule.start()
console.log(await CoreModule.getPort())
await CoreModule.getPort()
} catch (err) {
console.warn(err.message)
}

try {
subscriptions.eventStream.subscribe({
iterator: function * () {
try {
Expand Down
17 changes: 8 additions & 9 deletions client/react-native/common/relay/environment.js
Expand Up @@ -64,13 +64,6 @@ let getIP = () =>
return resolve(window.location.hostname)
}

// eslint-disable-next-line
if (__DEV__) {
return require('react-native-network-info').NetworkInfo.getIPV4Address(
ip => resolve(ip)
)
}

if (Platform.OS === 'ios') {
return resolve('127.0.0.1')
}
Expand Down Expand Up @@ -124,8 +117,14 @@ const perfLogger = (msg, req, res) => {
console.error(errorReason)
}

console.dir(req)
console.dir(res)
if (typeof req !== 'undefined') {
console.dir(req)
}

if (typeof res !== 'undefined') {
console.dir(res)
}

console.groupEnd()
} catch (_) {
console.log('[RELAY_NETWORK]', msg, req, res)
Expand Down
58 changes: 58 additions & 0 deletions client/react-native/ios/Berty.xcodeproj/project.pbxproj
Expand Up @@ -38,6 +38,7 @@
2DF0FFEE2056DD460020B375 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; };
3FD46C36ED444780B7A88579 /* libRNVectorIcons-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 404393F653304CE5B3D2FECF /* libRNVectorIcons-tvOS.a */; };
4345EBFF9B7A402B9CC2405B /* FontAwesome5_Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 229720DFD15E4E569BD1D6D2 /* FontAwesome5_Regular.ttf */; };
480E37C42190874600BE10A5 /* libRCTPushNotification.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 480E37A42190872400BE10A5 /* libRCTPushNotification.a */; };
48E2A93E2177575C005C6F40 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48E2A93D2177575C005C6F40 /* Logger.swift */; };
48FBC710B1FF4A4890B3C836 /* EvilIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4852AC444E8740FEAA4DFAE9 /* EvilIcons.ttf */; };
5097099ECB874846A7B9FA6A /* Entypo.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C98BB2E01D1E436A800597C6 /* Entypo.ttf */; };
Expand Down Expand Up @@ -302,6 +303,20 @@
remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4;
remoteInfo = "jschelpers-tvOS";
};
480E37A32190872400BE10A5 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 480E37922190872400BE10A5 /* RCTPushNotification.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTPushNotification;
};
480E37A52190872400BE10A5 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 480E37922190872400BE10A5 /* RCTPushNotification.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3D05745F1DE6004600184BB4;
remoteInfo = "RCTPushNotification-tvOS";
};
5E9157321DD0AC6500FF2AA8 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */;
Expand Down Expand Up @@ -398,6 +413,8 @@
2D16E6891FA4F8E400B85C8A /* libReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libReact.a; sourceTree = BUILT_PRODUCTS_DIR; };
315E18D636B840518CA9A54F /* RNImagePicker.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNImagePicker.xcodeproj; path = "../node_modules/react-native-image-picker/ios/RNImagePicker.xcodeproj"; sourceTree = "<group>"; };
404393F653304CE5B3D2FECF /* libRNVectorIcons-tvOS.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = "libRNVectorIcons-tvOS.a"; sourceTree = "<group>"; };
480E37922190872400BE10A5 /* RCTPushNotification.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTPushNotification.xcodeproj; path = "../node_modules/react-native/Libraries/PushNotificationIOS/RCTPushNotification.xcodeproj"; sourceTree = "<group>"; };
480E37C521908A6000BE10A5 /* Berty.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = Berty.entitlements; path = Berty/Berty.entitlements; sourceTree = "<group>"; };
4852AC444E8740FEAA4DFAE9 /* EvilIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = EvilIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf"; sourceTree = "<group>"; };
48B5C9A179E04E4CA39C6E06 /* RNVectorIcons.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNVectorIcons.xcodeproj; path = "../node_modules/react-native-vector-icons/RNVectorIcons.xcodeproj"; sourceTree = "<group>"; };
48E2A93D2177575C005C6F40 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -452,6 +469,7 @@
00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */,
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */,
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
480E37C42190874600BE10A5 /* libRCTPushNotification.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
895E8DFE9E05494099380954 /* libRNNetworkInfo.a in Frameworks */,
Expand Down Expand Up @@ -552,6 +570,7 @@
13B07FAE1A68108700A75B9A /* Berty */ = {
isa = PBXGroup;
children = (
480E37C521908A6000BE10A5 /* Berty.entitlements */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.m */,
Expand Down Expand Up @@ -598,6 +617,15 @@
name = Frameworks;
sourceTree = "<group>";
};
480E37932190872400BE10A5 /* Products */ = {
isa = PBXGroup;
children = (
480E37A42190872400BE10A5 /* libRCTPushNotification.a */,
480E37A62190872400BE10A5 /* libRCTPushNotification-tvOS.a */,
);
name = Products;
sourceTree = "<group>";
};
5E91572E1DD0AC6500FF2AA8 /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -641,6 +669,7 @@
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup;
children = (
480E37922190872400BE10A5 /* RCTPushNotification.xcodeproj */,
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */,
146833FF1AC3E56700842450 /* React.xcodeproj */,
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
Expand Down Expand Up @@ -852,6 +881,14 @@
DevelopmentTeam = WMBQ84HN4T;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
};
com.apple.Push = {
enabled = 1;
};
};
};
2D02E47A1E0B4A5D006451C7 = {
CreatedOnToolsVersion = 8.2.1;
Expand Down Expand Up @@ -904,6 +941,10 @@
ProductGroup = 00C302D41ABCB9D200DB3ED1 /* Products */;
ProjectRef = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */;
},
{
ProductGroup = 480E37932190872400BE10A5 /* Products */;
ProjectRef = 480E37922190872400BE10A5 /* RCTPushNotification.xcodeproj */;
},
{
ProductGroup = 139105B71AF99BAD00B5F7CC /* Products */;
ProjectRef = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */;
Expand Down Expand Up @@ -1172,6 +1213,20 @@
remoteRef = 3DAD3EAE1DF850E9000B6D8A /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
480E37A42190872400BE10A5 /* libRCTPushNotification.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTPushNotification.a;
remoteRef = 480E37A32190872400BE10A5 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
480E37A62190872400BE10A5 /* libRCTPushNotification-tvOS.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libRCTPushNotification-tvOS.a";
remoteRef = 480E37A52190872400BE10A5 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
Expand Down Expand Up @@ -1446,6 +1501,7 @@
ALWAYS_SEARCH_USER_PATHS = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Berty/Berty.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -1491,6 +1547,7 @@
ALWAYS_SEARCH_USER_PATHS = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Berty/Berty.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -1713,6 +1770,7 @@
ALWAYS_SEARCH_USER_PATHS = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Berty/Berty.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
Expand Down
32 changes: 32 additions & 0 deletions client/react-native/ios/Berty/AppDelegate.m
Expand Up @@ -10,6 +10,7 @@
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTPushNotificationManager.h>

@implementation AppDelegate

Expand Down Expand Up @@ -48,4 +49,35 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}

// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}

// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RCTPushNotificationManager didReceiveLocalNotification:notification];
}

@end
8 changes: 8 additions & 0 deletions client/react-native/ios/Berty/Berty.entitlements
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
22 changes: 13 additions & 9 deletions client/react-native/ios/Berty/Info.plist
Expand Up @@ -2,15 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>berty</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand All @@ -29,6 +20,15 @@
<string>0.0.488</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>berty</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down Expand Up @@ -74,6 +74,10 @@
<string>Zocial.ttf</string>
<string>AntDesign.ttf</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down

0 comments on commit f38b054

Please sign in to comment.