Home>

The uiactivityviewcontroller class is a standard view controller. By using this controller, your application can provide various services.This article introduces the uiactivityviewcontroller of the ios9 system sharing call. Friends who are interested can learn together.

The uiactivityviewcontroller class is a standard view controller. By using this controller, your application can provide various services.

The system provides some common standard services,For example, copy content to a pasteboard, post an announcement to a social network, or send content via email or sms.

Your application is responsible for configuring, presenting, and firing this view controller.

The configuration of the viewcontroller involves the specific data objects that the viewcontroller needs.(You can also specify a custom service list.Make your application support these services).

When presenting the view controller, it must be based on the current device type.Use the appropriate method.On the iPad, the view controller must be displayed through a popover. On the iPhone and ipodtouch, it must be displayed in a modal manner.

Yesterday, some netizens said that the system sharing code I wrote had a warning on ios9. Looking at the original uipopovercontroller was abandoned after ios8.The newly added uipopoverpresentationcontroller makes it easier to control popviews.

Here is my modified code:

1. Open other app previews as subviews in the app, only supported above 6.0

openappwithidentifier (appid:string)

2. Share text and picture information,Select view will pop up with focus on sourceview on ipad

share (texttoshare:string, url:string, image:uiimage, sourceview:uiview)
///Open other app previews as subviews in the app, only supported above 6.0
 private func openappwithidentifier (appid:string) {
 if let _=nsclassfromstring ("skstoreproductviewcontroller") {
  let storeproductviewcontroller=skstoreproductviewcontroller ()
  storeproductviewcontroller.delegate=self
  let dict=nsdictionary (object:appid, forkey:skstoreproductparameteritunesitemidentifier) ​​as! [string:anyobject]
  storeproductviewcontroller.loadproductwithparameters (dict, completionblock:{(result, error)->void in
//self.presentviewcontroller (storeproductviewcontroller, animated:true, completion:nil)
  })
  self.presentviewcontroller (storeproductviewcontroller, animated:true, completion:nil)
 } else {
  uiapplication.sharedapplication (). openurl (nsurl (string:"itms-apps://itunes.apple.com/app/id \ (appid)")!)
 }
 }
 ///Share text and picture information,Select view will pop up with focus on sourceview
 private func share (texttoshare:string, url:string, image:uiimage, sourceview:uiview) {
 let objectstoshare=[texttoshare, url, image]
 let activityviewcontroller=uiactivityviewcontroller (activityitems:objectstoshare, applicationactivities:nil)
 if uidevice.currentdevice (). userinterfaceidiom == uiuserinterfaceidiom.phone {
  self.presentviewcontroller (activityviewcontroller, animated:true, completion:nil)
 } else {
  let popover=activityviewcontroller.popoverpresentationcontroller
  if (popover!=nil) {
  popover?.sourceview=sourceview
  popover?.sourcerect=sourceview.frame
  popover?.permittedarrowdirections=uipopoverarrowdirection.any
  self.presentviewcontroller (activityviewcontroller, animated:true, completion:nil)
  }
 }
 }
ios
  • Previous js achieve secondary menu fade out
  • Next Detailed PHP + AJAX non-refreshing paging implementation method