I'm using swift with ios 8.3. I want to open settings app from my application. I know that using the code
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
will open my app settings. But I don't want to open my app settings. I just want to open the settings app and stay in the main page. If possible, navigate to "Cellular". Is there any way to acheive this?
Try this.
if let appSettings = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)
}
Xcode 11.5 - iOS > 10
Update on 11-Oct-2016:
It won't work in iOS10 anymore. So far I haven't found any workaround. If you guys have any solution please let me know. thanks.
======================================
if the iOS version <= iOS9, you need set URL types:
You can do in this way:
let url:NSURL! = NSURL(string : "prefs:root=")
UIApplication.sharedApplication().openURL(url)
I have a demo on github: http://github.com/zhihuitang/SettingDemo.git
And you can find all available URLs as follows:
http://iphonedevwiki.net/index.php/Preferences.app
Preferences app registers a private URL scheme, prefs:, the list below details opening specific views 1[2]
prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=General&path=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=General&path=USAGE
prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING
hope this helpful to you.
YES, They made changes in iOS 10, Please change "prefs:" to "App-Prefs:"
guard let profileUrl = URL(string:"App-Prefs:root=General&path=ManagedConfigurationList") else {
return
}
if UIApplication.shared.canOpenURL(profileUrl) {
UIApplication.shared.open(profileUrl, completionHandler: { (success) in
print(" Profile Settings opened: \(success)")
})
}
Related
I have a function inside my button to open up Apple Maps and search for Kebab.
However when Apple Maps is opening, Apple Maps have already chosen a Kebab restaurant, not showing the list with nearby restaurants as if you would search for it manually.
Ideas to fix this?
Get the list and not an executed search?
Button{
let url = URL(string:"maps://?saddr=&daddr=\("Kebab")")
if UIApplication.shared.canOpenURL(url!){
UIApplication.shared.open(url!, options: [:], completionHandler: nil)}
} label: {
Text("Find Kebab")
}
Firebase Dynamic Links not working iOS 15.1 for Facebook but working perfectly iOS 14.1. I have tried lot of changes with Dynamic Link parameters. I have checked all parameter configured correctly in the Firebase account and Dynamic link like App BundleId, AppStoreID, AppID and all others parameters.
For iOS 14.1
User post a dynamic link on facebook as a post. When user click on then facebook post redirect to automatically in the app.
For iOS 15.1
User post a dynamic link on facebook as post. When user click on facebook post, the user redirect default Website which i set in the dynamic link url.
User post a dynamic link on facebook as post. When user click on facebook post, the user redirect default Website which i set in the dynamic link url.
Code:-
func createLinkShare1(dynamicLinksDomainURIPrefix:String,link:URL) {
let appBundleID = AppInformation.AppBundleId
if let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix) {
linkBuilder.navigationInfoParameters = DynamicLinkNavigationInfoParameters()
linkBuilder.navigationInfoParameters?.isForcedRedirectEnabled = true
linkBuilder.iOSParameters = DynamicLinkIOSParameters(bundleID: appBundleID)
linkBuilder.iOSParameters?.appStoreID = AppInformation.AppStoreId
linkBuilder.iOSParameters?.minimumAppVersion = AppInformation.AppMinimumVersion
linkBuilder.androidParameters = DynamicLinkAndroidParameters(packageName: appBundleID)
linkBuilder.androidParameters?.minimumVersion = 0
linkBuilder.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder.socialMetaTagParameters!.title = "Testing "
linkBuilder.socialMetaTagParameters!.descriptionText = "Invite You"
guard let longDynamicLink = linkBuilder.url else {
print("ERROR in linkBuilder")
return
}
DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
if let error = error {
print("error shortening link: \(error.localizedDescription)")
return
}
if let url = url {
print("Share Url = ",url)
return
}
}
}
}
Firebase Dynamic Links not working Every Time Open Custom WebView (Redirection issue) Swift
Please check above code and let me know if i'm doing wrong anything, please correct me.
Can someone please explain to me how to show popup or deep working as expected in the Facebook case in the iOS 15., I've tried to with above code but no results yet.
Any help would be greatly appreciated.
Thanks in advance.
i am trying to add facebook share dialog into my ios application and i found the official page from facebook on how to do it, but i run into a problem about ContentProtocol. i dont know what that is. here is the link to the guidence that i use . it is pretty straight forward. basically just install the pod facebookshare, import it and add few line of code, but i got problem on 'myContent'
here is the code
import FacebookShare
let shareDialog = ShareDialog(content: myContent)
shareDialog.mode = .Native
shareDialog.failsOnInvalidData = true
shareDialog.completion = { result in
// Handle share results
}
try shareDialog.show()
here is the link
https://developers.facebook.com/docs/swift/sharing/share-dialog
what should i put in the myContent?
I guess next link is explained what you can use as content and how to use it
Content-types
(From documentation) Currently, the Facebook SDK for Swift can share 4 different kinds of content:
Links - Represented by the LinkShareContent object.
Photos - Represented by the PhotoShareContent object.
Videos - Represented by the VideoShareContent object.
Open Graph - Represented by the OpenGraphShareContent object.
you can use FBSDKShareLinkContent
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "//URL")
content.contentTitle = "MyApp"
content.contentDescription = "//Desc"
content.imageURL = NSURL(string:"//Image URL")
I'm trying to save an image to the photo library in Swift 3 (I'm working with Xcode 8).
ViewController Code:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
When I run the application, and click on the button to take the screenshot (converting it to image, ..., that's all working perfectly), the app asks for permission to access the photo library, I tap the "OK" button, and then the app crashes. The image is not saved in the photo library.
The only clue I get from Xcode is the following:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access file: 1} with userInfo dictionary {
reason = "Failed to access file: 1";
}
2016-09-28 11:24:27.216433 Ajax Kids[4143:1545362] [Migration] Unexpected error opening persistent store <private>, cannot attempt migration <private>)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store <private>. Requires update via assetsd (256: <private>)
Does anyone have any idea how to fix this?
Thanks in advance!
UPDATE
Sharing the image on Social Media works fine, so the problem is specified to saving the image in the photo library.
Add new records in your new InfoPlist.strings file.
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME)</string>
UPD: iOS 11 key
On iOS 11, there is a new property called NSPhotoLibraryAddUsageDescription, similar to NSPhotoLibraryUsageDescription. See https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
Try to force request permissions like this:
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
//do things
}
}
do not forget import Photos. Hope this helps.
I found the culprit in my particular case. We are using Leanplum for analytics and push notifications. The Leanplum.syncResourcesAsync method was causing the opening of the photo library to crash. It took a couple of days to find as I wasn't aware Leanplum was doing anything to hook into a user's photo library... which in itself is concerning.
We weren't using the functionality this particular method brings, so were able to just remove the method call and the photo library stopped crashing.
If someone has experience with WKWebView, please share how to make the background of the view transparent. The WebView object has such option via var drawsBackground: Bool { get set } but it is missing for the WKWebView class. I searched the net and .. found nothing. Before time it was possible to do so via opaque property, but not anymore. There is a getter isOpaque ... and that's it. I don't want to do it via CSS and already tried everything else, like:
webview.wantsLayer = true
webview.layer?.backgroundColor = NSColor.clear.cgColor
If someone can help ...
I. Nikolov
This should work for both macOS 10.11 and macOS 10.12:
if NSAppKitVersion.current.rawValue > 1500 {
webView.setValue(false, forKey: "drawsBackground")
}
else {
webView.setValue(true, forKey: "drawsTransparentBackground")
}
Remark: this has been passed by App Store review.
Your web page should have transparent background as well.