Unity 3D, How to: Remote Push Notifications [FREE] [NO SERVER REQUIRED]

Video:

Links:

[General]

[Android]

[iOS]

Codes:

OneSignalManager.cs


using System.Collections.Generic;
void Start () {
// Enable line below to enable logging if you are having issues setting up OneSignal. (logLevel, visualLogLevel)
// OneSignal.SetLogLevel(OneSignal.LOG_LEVEL.INFO, OneSignal.LOG_LEVEL.INFO);

OneSignal.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
.HandleNotificationOpened(HandleNotificationOpened)
.EndInit();

// Call syncHashedEmail anywhere in your app if you have the user's email.
// This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
// OneSignal.syncHashedEmail(userEmail);
}

// Gets called when the player opens the notification.
private static void HandleNotificationOpened(OSNotificationOpenedResult result) {
}</script>

NotificationService.m of OneSignalNotificationServiceExtension

#import "OneSignal.h"

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.receivedRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

[OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];

self.contentHandler(self.bestAttemptContent);
}

- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.

[OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];

self.contentHandler(self.bestAttemptContent);
}

@end

Comments

  • Hi there, your Tutorial was fine! Wasnt that hard as i thought. I got a question about OneSignal.  Is it possible to use oneSignal for a Chat app, like whatsapp. Sending Notification when u got a new Message?
  • Hi, I have AndroidManifest, the documentation says Make your changes to Assets / Plugins / Android / AndroidManifest.xml instead. I did so but the manifest does not work (my application uses a connection to the Internet). how do I do it right? Sorry for my English )
Sign In or Register to comment.