ios - Is it possible to include different content for different social media using UIActivityViewController? -


i using mobilecoreservices of ios 7 post content app social media. . , here code ..

nsarray *activityitems;  nsstring *title =  _titlelabel.text;  if (_imagelabel.image != nil) {     activityitems = @[title, _imagelabel.image]; } else {     activityitems = @[title]; }  uiactivityviewcontroller *activitycontroller = [[uiactivityviewcontroller alloc]  initwithactivityitems:activityitems  applicationactivities:nil];  [self presentviewcontroller:activitycontroller      animated:yes completion:nil]; 

now sends common text. wish post different titles facebook , twitter. possible?

i found tutorial helpful: http://www.albertopasca.it/whiletrue/2012/10/objective-c-custom-uiactivityviewcontroller-icons-text/

but gist of following:

  1. you need subclass uiactivityitemprovider

    @interface apcustomactivityprovider : uiactivityitemprovider <uiactivityitemsource> @end 
  2. add following implementation file

    @implementation apcustomactivityprovider - (id) activityviewcontroller:(uiactivityviewcontroller *)activityviewcontroller   itemforactivitytype:(nsstring *)activitytype {   if ( [activitytype isequaltostring:uiactivitytypeposttotwitter] ){     nsstring *title = @"twitter title";     return title;   }   if ( [activitytype isequaltostring:uiactivitytypeposttofacebook] ) {     nsstring *title = @"facebook title";     return title;   }   return nil; }  - (id) activityviewcontrollerplaceholderitem:(uiactivityviewcontroller*)activityviewcontroller { return @""; } @end 
  3. to use custom activityprovider, go presenting uiactivityviewcontroller

    nsarray *activityitems; apcustomactivityprovider *activityprovider = [[apcustomactivityprovider alloc] init]; if (_imagelabel.image != nil) {     activityitems = @[activityprovider, _imagelabel.image]; } else {     activityitems = @[activityprovider]; }   uiactivityviewcontroller *activitycontroller =  [[uiactivityviewcontroller alloc] initwithactivityitems:activityitems                                      applicationactivities:nil];  [self presentviewcontroller:activitycontroller                    animated:yes completion:nil]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -