Guide for setting up your IOS project
Here’s a streamlined guide for setting up your project:
1. Check Project Folders:
– Navigate to your project directory and locate the android
and ios
folders.
2. Open Terminal:
– Open the terminal in your project folder location.
3. Install Dependencies:
– Run the command: yarn install
to install all dependencies.
4. Update Dependencies:
– After installation, check and update any outdated packages.
5. Install CocoaPods (iOS only):
– Navigate to the ios
folder.
– Install CocoaPods by following the tutorials:
– [React Native Setup](https://reactnative.dev/docs/set-up-your-environment)
– [CocoaPods Installation Guide](https://guides.cocoapods.org/using/getting-started.html#installation)
6. Follow Video Tutorial:
– Refer to this video for guidance: [Setup Tutorial](https://www.youtube.com/watch?v=O5K0c6_xScw&t=127s)
7. Install and Link Push Notification Library:
– Install and link react-native-push-notification/ios
by following the instructions here:
– [Library GitHub Page](https://github.com/react-native-push-notification/ios)
8. Run pod-install
:
– Execute npx pod-install
in the terminal.
– Address any errors as needed. Solutions for common issues can be found here: [Error Solutions](https://awxdocs.com/tutorials/errors-and-solutions)
9. Open Project in Xcode:
– Double-click the {project_name}.xcworkspace
file in the ios
folder to open it in Xcode.
10. Configure Push Notifications in Xcode:
– In the Xcode project navigator, select your project (root folder).
– Under the Targets section, select your app target.
– Go to the “Signing & Capabilities” tab.
– Add the “Push Notifications” capability:
– Click the + Capability
button.
– Add “Background Modes” and check “Remote Notifications.”
– Add “Push Notifications.”
– Use the correct team under the Signing section, matching your Apple Developer account.
11. Update AppDelegate.h:
– At the top of the file, add:
1 |
#import <UserNotifications/UNUserNotificationCenter.h> |
– Update the AppDelegate
interface:
1 |
@interface AppDelegate : RCTAppDelegate <UNUserNotificationCenterDelegate> |
12. Update AppDelegate.m:
– Add the following methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for localNotification event. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNCPushNotificationIOS didReceiveNotificationResponse:response]; } // Required for handling notification when app is in foreground. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; return YES; } - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); } |
13. Update Build Settings in Xcode:
– In Xcode, select {project_name}
and go to “Build Settings.”
– Locate “Search Paths.”
– Select “Library Search Path”.
– Drag “inherited” to the bottom of the list by clicking on the <Multiple Values>
option.
14. Build and Run:
– Build and run the project as needed.
This guide should help you set up your project efficiently!