Copy Paste on ios

mghmgh USMember

I want to have an option to share a link via sms, but ios won't let you prompt a text message "You cannot specify the text that is placed in the message, nor can you force a message to be sent via code. Only the user can type and send the message."

I was thinking I could have a button that says "Click Here to Copy Link" then simply direct the user to sms and instruct them to paste the message. Unfortunantly I haven't found a way to copy text into the iphone's clipboard (if it has such a thing)

Any advice?

Answers

  • YkshLeoYkshLeo USMember ✭✭✭✭

    @mgh

    It's just a sample code, to share a message (title, content, links) in iOS

            public void ShareLink(string title, string status, string link)
            {
                var actionSheet = new UIActionSheet("Share on");
                foreach (SLServiceKind service in Enum.GetValues(typeof(SLServiceKind)))
                {
                    actionSheet.AddButton(service.ToString());
                }
                actionSheet.Clicked += delegate(object a, UIButtonEventArgs b)
                {
                    SLServiceKind serviceKind = (SLServiceKind)Enum.Parse(typeof(SLServiceKind), actionSheet.ButtonTitle(b.ButtonIndex));
                    ShareOnService(serviceKind, title, status, link);
                };
                actionSheet.ShowInView(UIApplication.SharedApplication.KeyWindow.RootViewController.View);
            }
    
            private void ShareOnService(SLServiceKind service, string title, string status, string link)
            {
                SLComposeViewController slComposer;
                if (SLComposeViewController.IsAvailable(service))
                {
                    slComposer = SLComposeViewController.FromService(service);
                    slComposer.SetInitialText(status);
                    if (title != null)
                        slComposer.SetInitialText(String.Format("{0} {1}", title, status));
                    else
                        slComposer.SetInitialText(status);
                    if (link != null)
                        slComposer.AddUrl(new NSUrl(link));
                    slComposer.CompletionHandler += (result) =>
                    {
                        UIApplication.SharedApplication.KeyWindow.RootViewController.InvokeOnMainThread(() =>
                        {
                            UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null);
                        });
                    };
                    UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(slComposer, true, null);
                }
            }
    

    Just make try with this code :smile:

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited October 2015

    @mgh

    Here is sample code defining copy and paste in clipboard.

            public void CopyToClipboard(String text)
            {
                UIPasteboard clipboard = UIPasteboard.General;
                clipboard.String = text;
            }
    
    
            public String PasteFromClipboard()
            {
                UIPasteboard clipboard = UIPasteboard.General;
                return clipboard.String;
            }
    

    Just have a try with this one :smile:

Sign In or Register to comment.