如何直接将文本和图像共享到whatsapp

时间:2016-03-23 05:12:30

标签: ios objective-c iphone

我需要share imagetext直接WhatsApp。我尝试使用actionsheetUIDocumentIntractionController

我尝试使用此代码:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
 [AdDetailsViewController processImageDataWithURLString:self.strThumbImage andBlock:^(NSData *imageData) {

            self.watsappShareimg = [[UIImage alloc]initWithData:imageData];

         }];
        UIImage     * iconImage = self.watsappShareimg; //[UIImage imageNamed:@"flag.png"];
        NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

        [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

        self.documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
        self.documentationInteractionController.UTI = @"net.whatsapp.image";
        self.documentationInteractionController.delegate = self;

        [self.documentationInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];


    } else {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }

提前感谢你

1 个答案:

答案 0 :(得分:3)

您可以使用#include <iostream> #include <boost/msm/back/state_machine.hpp> #include <boost/msm/front/state_machine_def.hpp> #include <boost/msm/front/functor_row.hpp> #include <boost/static_assert.hpp> namespace msm = boost::msm; namespace msmf = boost::msm::front; namespace mpl = boost::mpl; // StateMachine [Osm] // // (initial) // | // V // State1:StateSub --Event1--> State2 // // // StateMachine [StateSub] // // (initial) // | // V // SubState1 --Event2--> SubState2:StateSubSub // A | // +--------Event3------------+ // // // StateMachine [StateSubSub] // // (initial) // | // V // SubSubState1---Event4--> SubSubState2 // A | // +-----------Event5---------+ // ----- Events struct Event1 {}; struct Event2 {}; struct Event3 {}; struct Event4 {}; struct Event5 {}; // ----- State machine struct StateSubSub_:msmf::state_machine_def<StateSubSub_> { struct SubSubState1:msmf::state<> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSubSub_>::value)); std::cout << "SubSubState1::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSubSub_>::value)); std::cout << "SubSubState1::on_exit()" << std::endl; } }; struct SubSubState2:msmf::state<> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSubSub_>::value)); std::cout << "SubSubState2::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSubSub_>::value)); std::cout << "SubSubState2::on_exit()" << std::endl; } }; // Set initial state typedef mpl::vector<SubSubState1> initial_state; // Transition table struct transition_table:mpl::vector< // Start Event Next Action Guard msmf::Row < SubSubState1, Event4, SubSubState2, msmf::none, msmf::none >, msmf::Row < SubSubState2, Event5, SubSubState1, msmf::none, msmf::none > > {}; }; typedef msm::back::state_machine<StateSubSub_> StateSubSub; // ----- State machine struct StateSub_:msmf::state_machine_def<StateSub_> { struct SubState1:msmf::state<> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSub_>::value)); std::cout << "SubState1::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSub_>::value)); std::cout << "SubState1::on_exit()" << std::endl; } }; struct SubState2_:msmf::state_machine_def<SubState2_> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSub_>::value)); std::cout << "SubState2::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, StateSub_>::value)); std::cout << "SubState2::on_exit()" << std::endl; } struct Impl_:StateSubSub {}; typedef Impl_ initial_state; }; // Pick a back-end typedef msm::back::state_machine<SubState2_> SubState2; // Set initial state typedef mpl::vector<SubState1> initial_state; // Transition table struct transition_table:mpl::vector< // Start Event Next Action Guard msmf::Row < SubState1, Event2, SubState2, msmf::none, msmf::none >, msmf::Row < SubState2, Event3, SubState1, msmf::none, msmf::none > > {}; }; typedef msm::back::state_machine<StateSub_> StateSub; struct OuterSm_:msmf::state_machine_def<OuterSm_> { struct State1_:msmf::state_machine_def<State1_> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, OuterSm_>::value)); std::cout << "State1::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, OuterSm_>::value)); std::cout << "State1::on_exit()" << std::endl; } struct Impl_:StateSub {}; typedef Impl_ initial_state; }; // Pick a back-end typedef msm::back::state_machine<State1_> State1; struct State2:msmf::state<> { template <class Event,class Fsm> void on_entry(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, OuterSm_>::value)); std::cout << "State2::on_entry()" << std::endl; } template <class Event,class Fsm> void on_exit(Event const&, Fsm&) const { BOOST_STATIC_ASSERT((boost::is_convertible<Fsm, OuterSm_>::value)); std::cout << "State2::on_exit()" << std::endl; } }; // Set initial state typedef State1 initial_state; // Transition table struct transition_table:mpl::vector< // Start Event Next Action Guard msmf::Row < State1, Event1, State2, msmf::none, msmf::none > > {}; }; // Pick a back-end typedef msm::back::state_machine<OuterSm_> Osm; void test() { Osm osm; osm.start(); std::cout << "> Send Event2()" << std::endl; osm.process_event(Event2()); std::cout << "> Send Event4()" << std::endl; osm.process_event(Event4()); std::cout << "> Send Event5()" << std::endl; osm.process_event(Event5()); std::cout << "> Send Event3()" << std::endl; osm.process_event(Event3()); std::cout << "> Send Event1()" << std::endl; osm.process_event(Event1()); } int main() { test(); } 分享UIActivityViewControllerimagetext。这是Apple默认分享方法

URL

您可以尝试上面的代码https://www.whatsapp.com/faq/en/iphone/23559013 在此NSString *shareText = @"This is Sharable text"; UIImage * image = [UIImage imageNamed:@"Test.png"]; NSArray *array_Object = @[shareText, image]; UIActivityViewController *obj_activity = [[UIActivityViewController alloc] initWithActivityItems:array_Object applicationActivities:nil]; [self presentViewController:controller animated:YES completion:nil] 他们Link只共享独立文字。对于MentionedImageaudio使用Video