Schedule push notification Parse unity - parse-platform

Can i use Parse.com Unity plugin to schedule push notification to the user once an action is done.
i.e) Notify the user in 1 hour that his building has been built.(as in coc an example)

I don't think Push Notifications is what you are looking for here, instead I think you want Local Notifications. With Local Notifications, you schedule a notification to appear at a specified time (you usually schedule the notification when the player leaves the app, as you wouldn't normally want the notification to appear as they are playing it).
For example, you would do the following (not tested):
public void OnApplicationPause(bool isPaused)
{
// If paused, then in background
if (isPaused)
{
LocalNotification notification = new LocalNotification();
notification.alertAction = "App Name";
notification.alertBody = "The building is complete";
notification.hasAction = true;
notification.applicationIconBadgeNumber = 1; // Set's the badge count
notification.fireDate = dateBuildingWillBeFinished;
NotificationServices.ScheduleLocalNotification(notification);
}
else // Entered the app
{
// Clear notifications
NotificationServices.CancelAllLocalNotifications();
NotificationServices.ClearLocalNotifications();
}
}
Push Notifications are generally used to send messages to all players, or a group of players (such as players in the UK) to notify them of something, like a sale that is going on for in app purchases. Local Notifications are user specific, and can act more as reminders, such as your building has been completed or you haven't visited your town in a week etc.

Related

How to don't show Firebase notification when the application in Foreground on Xamarin iOS?

I'm developing a chat application, I use Firebase for push notification.
In Background and Foreground, Method DidReceiveRemoteNotification() work well.
But when the application in Foreground, I don't want to show Firebase notification because It annoys the user. I just want to handle the event when the application receives Firebase notification and don't show Firebase notification.
I tried removing 2 params alert-title and alert-body on config of Firebase:
First: http://{url}/demo?device-token={token}&alert-title={title}&alert-body={body}
Later: http://{url}/demo?device-token={token}
After changing Firebase config, I can't push Firebase notification when the application turns off.
So, I must use First config.
=> How to don't show Firebase notification when the application in Foreground on Xamarin iOS?
This is my code:
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
try
{
// App in Foreground
if (!_isInBackground)
{
// Foreground
if (userInfo?.ContainsKey(new NSString("payload")) == true)
{
// TODO: handle Foreground
return;
}
}
// App in Background
// Checking push notification message
if (userInfo?.ContainsKey(new NSString("payload")) == true)
{
var payload = userInfo[new NSString("payload")]?.ToString();
if (!string.IsNullOrEmpty(payload))
{
// TODO: handle Background
}
// Push notification message
PushNotificationManager.DidReceiveMessage(userInfo);
// Inform system of fetch results
completionHandler(UIBackgroundFetchResult.NewData);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
Please help me!
One possible way to show / hide notification when application is in foreground is to set UNNotificationPresentationOptions in AppDelegate FinishLaunching method.
By default when app is in foreground, UNNotificationPresentationOptions is set to None, causing notification to not show up when application is not in foreground. But for your case it seems that it is set to value other then None.
UNNotificationPresentationOptions is defined as
public enum UNNotificationPresentationOptions
{
Alert, //Display the notification as an alert, using the notification text.
Badge, //Display the notification badge value in the application's badge.
None, //No options are set.
Sound //Play the notification sound.
}
//To set for alert
FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert;
//You can also combine them
FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge;
Reference: https://github.com/CrossGeeks/FirebasePushNotificationPlugin/issues/6
From FCM document about receiving message ,
In iOS 10 and above, you can set the UNUserNotificationCenter delegate to receive display notifications from Apple and FIRMessaging's delegate property to receive data messages from FCM. If you do not set these two delegates with AppDelegate, method swizzling for message handling is disabled. You'll need to call appDidReceiveMessage: to track message delivery and analytics.
// Receive displayed notifications for iOS 10 devices.
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print message ID.
if (userInfo[kGCMMessageIDKey]) {
NSLog(#"Message ID: %#", userInfo[kGCMMessageIDKey]);
}
// Print full message.
NSLog(#"%#", userInfo);
// Change this to your preferred presentation option
completionHandler(UNNotificationPresentationOptionNone);
}
So you can change what to show (Or no alert) when meeage receive while app is in the foreground.If completionHandler set UNNotificationPresentationOptionNone then there will no alert. You can have a try with this way.
UNNotificationPresentationOptionNone : No alert.

Is it possible to run a timer task when the application is closed?

I have just completed learning Java, now I am working on creating Android apps. But I am not so expert in this field. I have just created an Android app which has some advertisements like banner ad, interstitial ad. I want to give an opportunity to the user to stop those Ads for 24 hours if they watch a video AD. But I'm not familiar with timer task any suggestion will be very appreciating. here is the code that I imagine :
// load from shared preference
SharedPreference spref = getSharedPreference("directory_name", 0);
if(spref.getBoolean("ad_key", false)==true){
// all ads should stop showing
}else{
// ads are showing
}
// help me here in timer task
As ad reward
--> start countadown
--> if(countDown>0){
doneWatchindAd(true);
}else{
doneWatchindAd(false);
}
// store to shared preference
public void doneWatchindAd(bollean cond){
SharedPreference spref = getSharedPreference("directory_name", 0);
SharedPreference.Editor editor = spref.edit();
editor.putBoolean("ad_key", cond);
editor.commit();
}

How can xamarin send local notification to specific users or Show/hide?

I am using android local notification in my app, all work fine,
but my question is:
Is there any way to send notification to specific users or group, Or to show/hide the notification to/from specific users?
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
.SetContentTitle("Button Clicked") // Set the title
.SetNumber(count) // Display the count in the Content Info
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm))
.SetDefaults(0)
.SetSmallIcon(Resource.Drawable.notify)
.SetVibrate(new long[] { 1000, 1000 })
.SetContentText(String.Format("The button has been clicked {0} times.", count)); // the message to display.
// Finally, publish the notification:
NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
notificationManager.Notify(ButtonClickNotificationId, builder.Build());
Is there any way to send notification to specific users or group, Or to show/hide the notification to/from specific users?
You will need to use UserManager to query Users, but to use that , your app need MANAGE_USERS permission, which has a protectionlevel of signature|system,which means that the application has to be signed with the platform key. You can refer to this case.

How to use the library PushSharp to send push notifications to iOS?

I am using the latest PushSharp version to send push notification through APN. I am using the below code given in their Git wiki page to send the notifications:
// Configuration (NOTE: .pfx can also be used here)
var config = new ApnsConfiguration (ApnsConfiguration.ApnsServerEnvironment.Sandbox,
"push-cert.p12", "push-cert-pwd");
// Create a new broker
var apnsBroker = new ApnsServiceBroker (config);
// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle (ex => {
// See what kind of exception it was to further diagnose
if (ex is ApnsNotificationException) {
var notificationException = (ApnsNotificationException)ex;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine ($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
} else {
// Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine ($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
};
apnsBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("Apple Notification Sent!");
};
// Start the broker
apnsBroker.Start ();
foreach (var deviceToken in MY_DEVICE_TOKENS) {
// Queue a notification to send
apnsBroker.QueueNotification (new ApnsNotification {
DeviceToken = deviceToken,
Payload = JObject.Parse ("{\"aps\":{\"badge\":7}}")
});
}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop ();
The confusions -
I don't know if the method apnsBroker.QueueNotification sends the push at all, or just queues it up.
I don't know if I need to install the apple certificate in some way on my Windows machine.
There is no proper sample code available online with the latest version of PushSharp.
Just fire the above code in a console application and Pushsharp will send the notifications.
Apple allow a single push token for a push notification at a time.
The code works as it. But there are some uncertain points as you said.
First notification will be send right away when you queue it, it is just a async mechanism to not to wait the code there. So if anything goes wrong (or right) you can handle it via broker's events.
Second part is a little complicated. First of all you have create a certificate for pushnotifications on a macOS machine. Than you have to upload it to your developer account etc. You can find videos how to that via google. It is pretty long to describe it here. Than you have to export your "Apple Push Services" certificate from your macOSmachine to a p12 file. And get and put that .p12 file to your .net service folder for example to "App_Data" folder and load it like (i assume you are writing a web service):
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox,
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "App_Data", "yourfileName.p12"),"yourFilePassword");
I hope that helps you.

Wp7:Push notification channel URI is null

We are trying to test push notifications, using the latest code from the documentation How to: Set Up a Notification Channel for Windows Phone
public HttpNotificationChannel myChannel;
public void CreatingANotificationChannel()
{
myChannel = HttpNotificationChannel.Find("MyChannel");
if (myChannel == null)
{
myChannel = new HttpNotificationChannel("MyChannel","www.contoso.com");
// An application is expected to send its notification channel URI to its corresponding web service each time it launches.
// The notification channel URI is not guaranteed to be the same as the last time the application ran.
myChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myChannel_ChannelUriUpdated);
myChannel.Open();
}
else // Found an existing notification channel.
{
// The URI that the application sends to its web service.
Debug.WriteLine("Notification channel URI:" + myChannel.ChannelUri.ToString());
}
myChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myChannel_HttpNotificationReceived);
myChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myChannel_ShellToastNotificationReceived);
myChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myChannel_ErrorOccurred);
}
If HttpNotificationChannel.Find() returns null, it opens a new channel, but the ChannelUriUpdated event is never triggered.
If HttpNotificationChannel.Find() returns a channel, the ChannelUri property is null. The sample code crashes here because it assumes the ChannelUri property to be not null.
In neither case is the ErrorOccurred event triggered.
How can i solve this problem? This problem is because of microsoft server or any thing else?
Thnks in advance
EDIT
Waiting for replay,after ten days i am suffering of null uri problem
Can any one tell me how can i solve this problem some time MSPN server give chanalk uri ans some time not i mean some time it give null reference Exception.
What Microsoft doing?
If I don't go wrong, www.contoso.com it's a example URI to demonstrate that you need to put your own server URL address, but in my experience, I never use in that way. I prefer just to put
myChannel = new HttpNotificationChannel("MyChannel");
Look this example (it's in Spanish) but the codes are very clear of what you need to do to set the push notification client and service.
I hope I helped you.
You are testing in what mobile are Emulator,
Do you have developer account subscription for windows phone development,
Had you Developer unlocked your mobile,
Noorul.
I think the problem is that you are using the HttpNotificationChannel constructor of the authenticated web service, according to the documentation.
Instead, you should use the constructor that takes only one parameter, as you can check in this example
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "ToastSampleChannel";
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
...
}
Hope it helps

Resources