<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andreas Beyer</title>
    <description>The latest articles on DEV Community by Andreas Beyer (@ndbeyer).</description>
    <link>https://dev.to/ndbeyer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1285129%2Fa8e491e4-93d5-4d13-9f0e-7466ddcf0c54.png</url>
      <title>DEV Community: Andreas Beyer</title>
      <link>https://dev.to/ndbeyer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ndbeyer"/>
    <language>en</language>
    <item>
      <title>Implement Remote Push Notification Badges (IOS) on background React Native Apps</title>
      <dc:creator>Andreas Beyer</dc:creator>
      <pubDate>Thu, 18 Jul 2024 12:54:26 +0000</pubDate>
      <link>https://dev.to/ndbeyer/react-native-remote-push-notification-badge-ios-1dj2</link>
      <guid>https://dev.to/ndbeyer/react-native-remote-push-notification-badge-ios-1dj2</guid>
      <description>&lt;p&gt;For me it was somewhat annoying to find the simplest path to implement remote push notifications (PN) badges (ios) on background React Native apps.&lt;/p&gt;

&lt;p&gt;I suppose you already have set up your PNs based on e.g. &lt;code&gt;firebase&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We don't use the following approaches&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the server controlled way setting &lt;code&gt;apns.payload.aps.badge&lt;/code&gt; (It is annoying to handle that logic for each user in the backend)&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;NotificationService.swift&lt;/code&gt; and &lt;code&gt;UserDefaults&lt;/code&gt; approach (it is ok to write Swift, but it is still annoying to use XCode)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok let's go:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure to request &lt;code&gt;badge&lt;/code&gt; permissions, this took me quite a while to check that this is required, otherwise you'll receive PNs but no badge will ever appear anywhere - there won't even be the badge slider available in your app settings.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { requestNotifications } from 'react-native-permissions'
...
React.useEffect(() =&amp;gt; {
   requestNotifications(['alert', 'badge'])
},[])

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a CloseStatePseudoApp to make sure that &lt;code&gt;firebaseMessagings&lt;/code&gt; background messages run even if the app is in closed state
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const MainApp  = () =&amp;gt; ...

const ClosedStatePseudoApp = () =&amp;gt; {
    React.useEffect(() =&amp;gt; {
        SplashScreen.hide();
    }, []);

    return null;
};

AppRegistry.registerComponent('YourAppname', (props) =&amp;gt;
    props?.isHeadless ? ClosedStatePseudoApp() : MainApp()
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install &lt;code&gt;@notifee/react-native&lt;/code&gt; (podinstall)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up &lt;code&gt;firebaseMessagingService.setBackgroundMessageHandler&lt;/code&gt; somewhere in a effect hook, and make sure to call the &lt;code&gt;notifee.incrementBadgeCount()&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import notifee from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
const messagingService = messaging();

React.useEffect(() =&amp;gt; {
   messagingService.setBackgroundMessageHandler(async (message:    RemoteMessage) =&amp;gt; {
        console.log('messagingService.backgroundMessage', message);
        await notifee.incrementBadgeCount();
    });
},[])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To reset the badge count to 0, once the app went foreground, use react natives AppState and notifee to do so
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { AppState } from 'react-native';
import notifee from '@notifee/react-native';

AppState.addEventListener('change', (nextAppState) =&amp;gt; {
    switch (nextAppState) {
        case 'active': {
            notifee.setBadgeCount(0);
        }
        default:
            return;
    }
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>ios</category>
      <category>notifications</category>
      <category>badge</category>
    </item>
    <item>
      <title>React Native Paypal integration</title>
      <dc:creator>Andreas Beyer</dc:creator>
      <pubDate>Mon, 19 Feb 2024 20:18:58 +0000</pubDate>
      <link>https://dev.to/ndbeyer/react-native-paypal-integration-104j</link>
      <guid>https://dev.to/ndbeyer/react-native-paypal-integration-104j</guid>
      <description>&lt;p&gt;I recently undertook the task of integrating PayPal into a React Native project. My initial approach followed the guides of &lt;a href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwjtnaKoiriEAxUAbfEDHf5tB7kQFnoECBoQAQ&amp;amp;url=https%3A%2F%2Fwww.codecentric.de%2Fwissens-hub%2Fblog%2Fpaypal-integration-with-react-native&amp;amp;usg=AOvVaw2AmS-MZcCHe5VhAH8GCgVO&amp;amp;opi=89978449"&gt;codecentric&lt;/a&gt; and &lt;a href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwjtnaKoiriEAxUAbfEDHf5tB7kQFnoECBIQAQ&amp;amp;url=https%3A%2F%2Fblog.logrocket.com%2Fhow-to-integrate-paypal-payments-with-react-native%2F&amp;amp;usg=AOvVaw2rpUlHztJDKcMSPeH5Qv5n&amp;amp;opi=89978449"&gt;Logrocket&lt;/a&gt;, which relied on utilizing PayPal's Smart Payment Buttons within a React (web) application. However, I found this method to be somewhat suboptimal for two reasons.&lt;/p&gt;

&lt;p&gt;Firstly, it needs an additional dependency - the React (web) application hosting PayPal's Smart Payment Buttons. This, coupled with the bridging setup required to facilitate communication between React Native Webview and the React Web deployment, adds unnecessary complexity.&lt;/p&gt;

&lt;p&gt;Secondly, you start the payment Process with PayPal's Smart Payment Buttons, which directly communicate with the paypal api and in the end return you an order id, which you then need to report to your own API again. But what about cases, where users should not be able to start a new payment process, because they have already paid the product or because they already have a PayPal subscription (and need to upgrade). You have to handle these things in the frontend and ask your API before you show PayPal's Smart Payment Buttons to your users. Another unnecessary step that adds to application complexity.&lt;/p&gt;

&lt;p&gt;Alternatively, we can streamline the process by leveraging PayPal's HATEOAS links. When &lt;a href="https://developer.paypal.com/docs/api/orders/v2/#orders_create"&gt;creating a PayPal order&lt;/a&gt; via the PayPal REST API, PayPal returns a payer_action link. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5q1jvxsycbzuvusdn4t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5q1jvxsycbzuvusdn4t.png" alt="Image description" width="800" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fditpesp5w34swpdno25h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fditpesp5w34swpdno25h.png" alt="Image description" width="800" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, when &lt;a href="https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create"&gt;creating a PayPal subscription&lt;/a&gt;, an approve link is provided. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w12feh8f6svhvwbo80d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w12feh8f6svhvwbo80d.png" alt="Image description" width="800" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqrdxoqrku6fzw752eir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqrdxoqrku6fzw752eir.png" alt="Image description" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By utilizing these links generated via our API and transmitting them to the React Native app, we can stick them into e.g. React Native Webview and the user can start the payment approval process.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
