Example #1
0
        public void JPushSetAlias(string aliasName)
        {
            ObjCRuntime.Selector sel = new ObjCRuntime.Selector("tagsAliasCallback");
            NSObject             obj = new NSObject();

            JPUSHService.SetAlias(aliasName, sel, obj);
        }
 public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
 {
     // Override point for customization after application launch.
     // If not required for your application you can safely delete this method
     JPUSHService.SetAlias("ss", TestEvent, 11);
     return(true);
 }
Example #3
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            string token = deviceToken.Description;

            token = token.Replace(" ", "");
            token = token.Replace(">", "");
            token = token.Replace("<", "");
            System.Console.WriteLine(token);
            JPUSHService.RegisterDeviceToken(token);
        }
Example #4
0
        public void Register(AppDelegate app, NSDictionary options)
        {
            //注册apns远程推送
            string advertisingId = AdSupport.ASIdentifierManager.SharedManager.AdvertisingIdentifier.AsString();

            this.entity       = new JPushRegisterEntity();
            this.entity.Types = 1 | 2 | 3;//entity.Types = (nint)(JPAuthorizationOptions.Alert) | JPAuthorizationOptions.Badge | JPAuthorizationOptions.Sound;
            JPUSHService.RegisterForRemoteNotificationConfig(entity, this);
            JPUSHService.SetupWithOption(options, JPushAppKey, Channel, true, advertisingId);
            JPUSHService.RegistrationIDCompletionHandler(app.GetRegistrationID);
        }
Example #5
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            JPUSHRegisterEntity entity = new JPUSHRegisterEntity();

            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                entity.Types = (nint)((long)JPAuthorizationOptions.Alert | (long)JPAuthorizationOptions.Badge | (long)JPAuthorizationOptions.Sound | (long)JPAuthorizationOptions.ProvidesAppNotificationSettings);
            }
            else
            {
                entity.Types = (nint)((long)JPAuthorizationOptions.Alert | (long)JPAuthorizationOptions.Badge | (long)JPAuthorizationOptions.Sound);
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                // 可以添加自定义categories
                //if(UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                //{
                //      NSSet<UNNotificationCategory *> *categories;
                //    NSSet categories = null;
                //   entity.Categories = categories;
                //}
                //else
                //{
                //      NSSet<UIUserNotificationCategory *> *categories;
                //   NSSet categories = null;
                //    entity.Categories = categories;
                //}
            }

            JPUSHService.RegisterForRemoteNotificationConfig(entity, new PUSHRegisterDelegate());
            JPUSHService.SetupWithOption(options, "3e56b44642dba83d39839e88", "Channel", true);

            JPUSHService.RegistrationIDCompletionHandler((resCode, registrationID) =>
            {
                if (resCode == 0)
                {
                    System.Diagnostics.Debug.WriteLine("registrationID获取成功:" + registrationID);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("registrationID获取失败:" + registrationID);
                }
            });

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Example #6
0
        /// <summary>
        /// 给极光deviceToken
        /// </summary>
        /// <param name="application">Application.</param>
        /// <param name="deviceToken">Device token.</param>
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            JPUSHService.RegisterDeviceToken(deviceToken);
            string tokenstr = deviceToken.Description;

            tokenstr = tokenstr.Replace("<", "");
            tokenstr = tokenstr.Replace(">", "");
            tokenstr = tokenstr.Replace(" ", "");

            Console.WriteLine("deviceToken===" + tokenstr);
            App.deviceToken = tokenstr;
            App.pushDeviceTokenToServie();
        }
Example #7
0
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            NSDictionary aps = (NSDictionary)userInfo["aps"];

            SharedData.Instance.Values["checknum"] = aps["alert"];
            JPUSHService.HandleRemoteNotification(userInfo);
            application.ApplicationIconBadgeNumber = 0;
            this.goToMessageViewControllerWith(userInfo);

            MsgBoxHelper.ShowMessage("接到到推送的消息", new string(userInfo.SelectMany(kv => string.Format("'{0}':'{1}'\n", kv.Key, kv.Value)).ToArray()));
            if (completionHandler != null)
            {
                completionHandler(UIBackgroundFetchResult.NewData);
            }
        }
 public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
 {
     if (message.Name == "UserId")
     {
         Console.WriteLine("用户id" + message.Body);
         string alias = message.Body.ToString().Replace("-", "").ToLower();
         if (string.IsNullOrWhiteSpace(alias))
         {
             JPUSHService.DeleteAlias((arg0, arg1, arg2) => { }, 1);
         }
         else
         {
             JPUSHService.SetAlias(alias, (arg0, arg1, arg2) => {
             }, 1);
         }
     }
 }
        /// <summary>
        /// 后台收到通知
        /// </summary>
        /// <param name="center"></param>
        /// <param name="response"></param>
        /// <param name="completionHandler"></param>
        public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
        {
            Console.WriteLine("DidReceiveNotificationResponse:");
            var content  = response.Notification.Request.Content;
            var userInfo = response.Notification.Request.Content.UserInfo;

            if (typeof(UserNotifications.UNPushNotificationTrigger) == response.Notification.Request.Trigger.GetType())
            {//远程通知
                System.Console.WriteLine(" 收到远程通知,Title:{0} -SubTitle:{1}, -Body:{2}", content.Title, content.Subtitle, content.Body);
                this.AddNotificationToView(content);
                JPUSHService.HandleRemoteNotification(userInfo);
            }
            else
            {//本地通知
            }

            if (completionHandler != null)
            {
                completionHandler();
            }
        }
        /// <summary>
        /// 前台收到通知,IOS10 support
        /// </summary>
        /// <param name="center"></param>
        /// <param name="notification"></param>
        /// <param name="completionHandler"></param>
        public override void WillPresentNotification(UserNotifications.UNUserNotificationCenter center, UserNotifications.UNNotification notification, Action <nint> completionHandler)
        {
            Console.WriteLine("WillPresentNotification:");
            var content  = notification.Request.Content;
            var userInfo = notification.Request.Content.UserInfo;

            if (typeof(UserNotifications.UNPushNotificationTrigger) == notification.Request.Trigger.GetType())
            {//远程通知
                System.Console.WriteLine(" 收到远程通知,Title:{0} -SubTitle:{1}, -Body:{2}", content.Title, content.Subtitle, content.Body);
                this.AddNotificationToView(content);

                JPUSHService.HandleRemoteNotification(userInfo);
            }
            else
            {//本地通知
            }

            if (completionHandler != null)
            {
                completionHandler(4);//UNNotificationPresentationOptions: None = 0,Badge = 1,Sound = 2,Alert = 4,
            }
        }
Example #11
0
        public void setAliasWithName(string userid)
        {
            if (!string.IsNullOrWhiteSpace(userid))
            {
                string alias = userid.Replace("-", "");
                JPUSHService.SetAlias(alias, (arg0, arg1, arg2) => { }, 1);

                //string[] tags = App.FrameworkURL.Split(":");
                //string tag = "";
                //if (tags.Count() > 1)
                //{
                //    tag = tags[1];
                //    tag = tag.Replace("//", "");
                //    tag = tags[0] + tag;
                //}
                //Console.WriteLine(" ios SetAlias userid = " + userid);
                //NSSet<NSString> nSSet = new NSSet<NSString>(new NSString[] { (NSString)tag });
                //JPUSHService.SetTags(nSSet, (arg0, arg1, arg2) => { }, 1);
            }
            else
            {
                JPUSHService.DeleteAlias((arg0, arg1, arg2) => { }, 1);
            }
        }
Example #12
0
 public void setAliasWithName(string name)
 {
     JPUSHService.SetAlias("", (arg0, arg1, arg2) => { }, new nint());
 }
 /// <summary>
 /// 给极光deviceToken
 /// </summary>
 /// <param name="application">Application.</param>
 /// <param name="deviceToken">Device token.</param>
 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
 {
     Console.WriteLine("给极光token");
     JPUSHService.RegisterDeviceToken(deviceToken);
 }
Example #14
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            Window.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            #region 极光推送注册
            MsgBoxHelper.Initialize(this);
            if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 10.0)
            {
                UNUserNotificationCenter center = UNUserNotificationCenter.Current;
                center.RequestAuthorization((UNAuthorizationOptions.CarPlay | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge), (bool arg1, NSError arg2) =>
                {
                    if (arg1)
                    {
                        Console.WriteLine("ios 10 request notification success");
                    }
                    else
                    {
                        Console.WriteLine("IOS 10 request notification failed");
                    }
                });
            }
            else if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 8.0)
            {
                UIUserNotificationSettings notiSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(notiSettings);
            }
            else
            {
                UIRemoteNotificationType myTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Badge;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(myTypes);
            }

            /*
             * JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false);
             * 将上面代码中的应用程序码换成你在极光服务器上注册的应用码,通过极光服务器发送推送消息,在真机上测试即可收到。
             */
            JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false);
            JPUSHService.SetDebugMode();
            UIApplication.SharedApplication.RegisterForRemoteNotifications();
            //JPUSHService.RegistrationIDCompletionHandler((int arg1, NSString arg2) =>
            //{
            //	if (arg1 == 0)
            //		Console.WriteLine(arg2);
            //});
            if (launchOptions != null)
            {
                NSDictionary remoteNotification = (NSDictionary)(launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey));
                if (remoteNotification != null)
                {
                    Console.WriteLine(remoteNotification);
                    this.goToMessageViewControllerWith(remoteNotification);
                }
            }
            #endregion
            Window.RootViewController = new UINavigationController(new ViewController());
            // make the window visible
            Window.MakeKeyAndVisible();

            return(true);
        }
 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
 {
     System.Diagnostics.Debug.WriteLine("Device Token: " + deviceToken.Description);
     JPUSHService.RegisterDeviceToken(deviceToken);
 }
 public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
 {
     JPUSHService.ShowLocalNotificationAtFront(notification, null);
 }
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            JPUSHService.HandleRemoteNotification(userInfo);

            completionHandler(UIBackgroundFetchResult.NewData);
        }