// AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{_window = new UIWindow(UIScreen.MainScreen.Bounds);
var setup = new Setup(this, _window);
setup.Initialize();
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
_window.MakeKeyAndVisible();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var settings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
else
{
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
return true;
}
public override void DidRegisterUserNotificationSettings (UIApplication application, UIUserNotificationSettings notificationSettings)
{
application.RegisterForRemoteNotifications ();
}
public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
{
DeviceToken = deviceToken;
// Register (deviceToken);
}
public override void FailedToRegisterForRemoteNotifications (UIApplication application, NSError error)
{
new UIAlertView("Error registering push notifications", error.LocalizedDescription, null, "OK", null).Show();
}
//service
public async void RegisterPushMessage ()
{
try
{
if (AppDelegate.DeviceToken == null)
{
return;
}
ParseInstallation currentInstallation=new ParseInstallation();
currentInstallation.SetDeviceTokenFromData(AppDelegate.DeviceToken);
currentInstallation.Channels=new List<string> { "" };
currentInstallation["user"]=ParseUser.CurrentUser;
await currentInstallation.SaveAsync();
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine (ex.ToString ()+"\n0000000000000000000");
}
}
public async void PushMessage (string FrienduserId,string MessageBoy)
{
try
{
var user = await ParseUser.Query.GetAsync (FrienduserId);
var push = new ParsePush();
push.Alert = ParseUser.CurrentUser.Username+": "+MessageBoy;
push.Channels = new List<string> {""};
//push.Expiration = new DateTime(2015,9, 23);
push.Query=ParseInstallation.Query.WhereEqualTo("user",user);
await push.SendAsync ();
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine (ex.ToString ()+"\n111111111111");
}
}
// https://parse.com/docs/dotnet/guide#push-notifications-push-localization