I'm using the permission_handler package for flutter. I'm successfully asking for the permissions on the camera, camera roll and the microphone.
But there is nothing popping up that asks me for the location.
I'm using this snippet to ask for the permission in my onboarding screen:
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
Permission.storage,
Permission.camera,
Permission.photos,
Permission.microphone,
].request().whenComplete(() {
print('Permission.location.status');
print(Permission.location.status);
///load main
_onIntroEnd(context);
});
This is the post_install in my podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
# You can enable the permissions needed here. For example to enable camera
# permission, just remove the `#` character in front so it looks like this:
#
# ## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1'
#
# Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=1',
## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=1',
## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=1',
## dart: PermissionGroup.camera
'PERMISSION_CAMERA=1',
## dart: PermissionGroup.microphone
'PERMISSION_MICROPHONE=1',
## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=1',
## dart: PermissionGroup.photos
'PERMISSION_PHOTOS=1',
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',
## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=1',
## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=1',
## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=1',
## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=1',
## dart: PermissionGroup.appTrackingTransparency
# 'PERMISSION_APP_TRACKING_TRANSPARENCY=1'
]
end
end
end
and this is my info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>WunderKlub</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<!-- Permission options for the `camera` group -->
<key>NSCameraUsageDescription</key>
<string>WunderKlub macht nur Spass mit Kamera.</string>
<!-- Permission options for the `microphone` group -->
<key>NSMicrophoneUsageDescription</key>
<string>Das Mikro nutzt WunderKlub gar nicht, es muss aber trotzdem abgefragt werden.</string>
<!-- Permission options for the `photos` group -->
<key>NSPhotoLibraryUsageDescription</key>
<string>WunderKlub möchte deine Fotos speichern können.</string>
<!-- Permission options for the `location` group -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location when in use</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always and when in use!</string>
<key>NSLocationUsageDescription</key>
<string>Older devices need location.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I have location always?</string>
</dict>
</plist>
This was very strange, in the end I restarted my Mac and my IPhone and it worked. Sometimes it is as simple as that.
Related
I am using a permission_handler 4.4.0(latest update) plugin to handle permissions on mobile devices which works perfectly on android devices but when i am trying to ask for permissions on iOS it doesn't show permission pop on device and returns the permission status unknown. I think so it might be missing into the info.plist or pod file but I followed and double checked the both files but I didn;t find anything wrong but i uploaded code for that files if someone finds anything missing or wrong into files. please look into the code and let me know your suggestions. Thanks in advance guys.
info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>driverapp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<!-- Permission options for the `location` group -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need Location for Route Map and AppMarker Jobs</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need Location for Patrolling and AppMarker Jobs</string>
<key>NSLocationUsageDescription</key>
<string>Need Location for Patrolling and AppMarker Jobs</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Need Location for Patrolling feature</string>
<key>PermissionGroupNotification</key>
<string>To show the notifications</string>
</dict>
</plist>
podfile
# Uncomment this line to define a global platform for your project
platform :ios, '10.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end
target 'Runner' do
# Flutter Pod
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'
# Plugin Pods
pod 'Firebase/Analytics'
pod 'Firebase/Database'
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=0',
## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=0',
## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=0',
## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=0',
## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=0',
## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=0',
## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=0',
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=0',
## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=0',
## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=0',
## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=0'
]
end
end
end
flutter code
Future<bool> checkForDevicePermission() async {
var status = await PermissionManager.checkForPermissions(
Platform.isAndroid? PermissionManager.androidPermissionsList:PermissionManager.iOSPermissionsList);
if (status != null) {
//status returned here is PermissionStatus.unknown for all permissions
//further code
}
}
//PermissionManager Function
static Future<Map<PermissionGroup, PermissionStatus>> checkForPermissions(
List<PermissionGroup> permissions) async {
List<PermissionGroup> neededPermissions = List<PermissionGroup>();
for (var permission in permissions) {
permissionStatus =
await PermissionHandler().checkPermissionStatus(permission);
if (permissionStatus == PermissionStatus.unknown ||
permissionStatus == PermissionStatus.denied) {
neededPermissions.add(permission);
}
}
if (neededPermissions != null && neededPermissions.length > 0) {
//getting the all permission status means granted or denied for which are requested to user
try {
Map<PermissionGroup, PermissionStatus> permissionsStatusList =
await PermissionHandler().requestPermissions(neededPermissions);
print(permissionsStatusList);
return permissionsStatusList;
} catch (e) {
print(e.toString());
return null;
}
} else {
return null;
}
}
There is no error logs in debug console when it asks for permissions
Your Pod file is incorrect. It's comments say:
# You can remove unused permissions here
# for more infomation: https://github.com/Baseflow/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
So, if you want to not use location services and don't want to ask for location services related permission then only write below line:
'PERMISSION_LOCATION=0',
Since you have written above line, while building Pod will exclude code from permission_handler package related to location permission. Hence even if you invoke permission popup for location from flutter code it will always return permission staus unknown.
I ran into this issue on iOS 14.1 -- it worked on the Simulator but failed on the real device in TestFlight and via USB.
I originally had the location call as:
/// Bad
await Permission.location.request().isGranted
And changed it to this, where it worked as expected:
/// Good
await Permission.locationWhenInUse.request().isGranted
There is also Permission.locationAlways.request().... as well
I am trying to associate a certain filename extension with my macOS application, which I have managed to do by following this guide and can drag my file in to my application.
When I drag my file in, I get this exception in the console:
2017-11-06 09:56:23.944202+0000 Test App[64192:2356795] [General] readFromData:ofType:error: is a subclass responsibility but has not been overridden.
2017-11-06 09:56:23.958166+0000 Test App[64192:2356795] [General] (
0 CoreFoundation 0x00007fff45f560fb exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff6c844c76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff45fe7bfd +[NSException raise:format:] + 205
3 AppKit 0x00007fff43a0b860 -[NSDocument readFromData:ofType:error:] + 253
4 AppKit 0x00007fff43a0b544 -[NSDocument readFromURL:ofType:error:] + 620
5 AppKit 0x00007fff436eb9b9 -[NSDocument _initWithContentsOfURL:ofType:error:] + 172
6 AppKit 0x00007fff436eb89e -[NSDocument initWithContentsOfURL:ofType:error:] + 231
7 AppKit 0x00007fff437c12dd -[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 628
8 AppKit 0x00007fff43a42578 __97-[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:]_block_invoke + 91
9 AppKit 0x00007fff43a42512 -[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:] + 176
10 AppKit 0x00007fff437c0493 __80-[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]_block_invoke + 880
11 AppKit 0x00007fff43a411b9 __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_4 + 31
12 AppKit 0x00007fff43a41542 __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_2.970 + 149
13 AppKit 0x00007fff43a4147d __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke.969 + 138
14 AppKit 0x00007fff43a4133f __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke.964 + 254
15 CoreFoundation 0x00007fff45eee52c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
16 CoreFoundation 0x00007fff45ed0f43 __CFRunLoopDoBlocks + 275
17 CoreFoundation 0x00007fff45ed0d08 __CFRunLoopRun + 3128
18 CoreFoundation 0x00007fff45ecfe43 CFRunLoopRunSpecific + 483
19 HIToolbox 0x00007fff451ef866 RunCurrentEventLoopInMode + 286
20 HIToolbox 0x00007fff451ef5d6 ReceiveNextEventCommon + 613
21 HIToolbox 0x00007fff451ef354 _BlockUntilNextEventMatchingListInModeWithFilter + 64
22 AppKit 0x00007fff434ec9f7 _DPSNextEvent + 2085
23 AppKit 0x00007fff43c81d98 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
24 AppKit 0x00007fff434e1805 -[NSApplication run] + 764
25 AppKit 0x00007fff434b09a6 NSApplicationMain + 804
26 Test App 0x000000010004cd1d main + 13
27 libdyld.dylib 0x00007fff6d433145 start + 1
28 ??? 0x0000000000000003 0x0 + 3
I've tried implementing the NSApplicationDelegate openFile functions but none of them are called when I drag the file on to the app:
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func application(_ application: NSApplication, open urls: [URL]) {
}
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
return false
}
func application(_ sender: NSApplication, openFiles filenames: [String]) {
}
func application(_ sender: NSApplication, openTempFile filename: String) -> Bool {
return false
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
How do I get access to the filename and contents of the "dragged in" file? I am using XCode 9.0.1 and Swift 4.
Edit:
Here is my Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>tal</string>
</array>
<key>CFBundleTypeIconFile</key>
<string></string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string></string>
</array>
<key>CFBundleTypeName</key>
<string>Layout File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.testapp.layout</string>
</array>
<key>LSTypeIsPackage</key>
<integer>0</integer>
<key>NSDocumentClass</key>
<string>NSDocument</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>v1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string></string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.video</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Layout File</string>
<key>UTTypeIconFile</key>
<string></string>
<key>UTTypeIdentifier</key>
<string>com.testapp.layout</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>tal</string>
</array>
</dict>
</dict>
<dict/>
</array>
</dict>
</plist>
So I would have expected application(_ sender: NSApplication, openFile filename: String) to be called when I drag the file on to the app when it's in the Dock...
There are a number of points here to address:
if you're working in macOS 10.12 or below, you should implement either openFile or openFiles. openURLs is 10.13+ - but you definitely don't need both
openFile will be called for each of multiple files; if openFiles is present, openFile will not be called, even if you open only a single file
I have no idea what openTempFile (or openUntitledFile) are about; I haven't been able to get anyone to call either
openFile(s) get called when you have successfully registered a UTI with the system; double-clicking an appropriate file(s) in the Finder, choosing 'open' or dragging the file onto the dock icon of your app all send an open message that gets handled by the AppDelegate.
I am not clear what you mean by 'When I drag my file in': if you drag your file onto the app icon in the Finder, openFile(s) should be called; your wording makes me think that your drag destination is part of your application's interface, in which case you need to handle dragging yourself.
Also check - because the linked (iOS) guide does not address this - that you have set your NSDocument class: your example says 'NSDocument', but there is an extreme likelihood that your application uses a custom subclass; so you need to set the 'Class' to that name.
I did the following upgrades to my Swift project
iOS 9, XCode 7.1, El Captain
Alamofire 1.3 -> 3.1.2
I get the following error while connecting to a self signed (test) web service.
Error Message
2015-11-12 21:46:13.045 [72695:5258083] CFNetwork SSLHandshake failed
(-9801) 2015-11-12 21:46:13.046 [72695:5258083]
NSURLSession/NSURLConnection HTTP load failed
(kCFStreamErrorDomainSSL, -9801) 2015-11-12 21:46:13.051 [Error]
[DeviceInfo.swift:277] generateUserToken > Error while processing
generateUserToken() : Optional(Error Domain=NSURLErrorDomain
Code=-1200 "An SSL error has occurred and a secure connection to the
server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9801,
NSLocalizedRecoverySuggestion=Would you like to connect to the server
anyway?, NSUnderlyingError=0x7ffa99a0b8c0 {Error
Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)"
UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
_kCFNetworkCFStreamSSLErrorOriginalValue=-9801, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9801}}, NSLocalizedDescription=An SSL error has occurred and a secure
connection to the server cannot be made.,
I have implemented the below code to disable SSL validation as per https://github.com/Alamofire/Alamofire#security
class CustomServerTrustPolicyManager: ServerTrustPolicyManager {
override func serverTrustPolicyForHost(host: String) -> ServerTrustPolicy? {
var policy: ServerTrustPolicy?
policy = ServerTrustPolicy.DisableEvaluation
return policy
}
}
public class NetworkManager {
static let sharedInstace = NetworkManager()
let defaultManager : Manager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"myservice.com": .DisableEvaluation
]
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPAdditionalHeaders = Alamofire.Manager.defaultHTTPHeaders
return Alamofire.Manager(
configuration: configuration,
serverTrustPolicyManager: CustomServerTrustPolicyManager(policies: serverTrustPolicies)
)
}()
}
Also, I have added the below entry in info.plist but no luck.
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>myservice.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSRequiresCertificateTransparency</key>
<true/>
</dict>
</dict>
</dict>
</dict>
Has anyone successfully connected self signed service using Alamofire & iOS9? Please advice.
I have a problem with my Titanium app ... I looked for some tutorials on the internet and Appcelerator on facebook module, more specifically login / logout. I'm trying to adjust this error the day, but I can not in any way ... I am offering my project for download if you can download and test would be helpful!
I'm trying to log in to android, but the app has to be for ios too ... if you can tell me how I do for me two or indicate items that really work ....
Download my Project: http://we.tl/hqvEpb2aeG
Below my files:
Login.js
//Abir Fluxo de Caixa
function openFluxoDeCaixa(){
var winFluxo = Alloy.createController('fluxo').getView();
winFluxo.open();
}
fb.addEventListener('login', fbLogin);
$.btnLoginFacebook.addEventListener('click',function(e){
fb.authorize();
});
function fbLogin(e){
fb.removeEventListener('login', fbLogin);
if(e.success){
var fbdata = {};
fbdata = JSON.parse(e.data);
var uFoto = 'https://graph.facebook.com/' + fbdata.id + '/picture?width=300&height=300';
var uNome = fbdata.name;
var slipName = uNome.split(" ");
Ti.App.Properties.setString('logged', 'true');
Ti.App.Properties.setString('foto', uFoto);
Ti.App.Properties.setString('nome', slipName[0]);
openFluxoDeCaixa();
}
}
$.windowLogin.open();
Alloy.js
var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();
if(OS_ANDROID){
$.windowLogin.fbProxy = fb.createActivityWorker({lifecycleContainer: $.windowLogin});
}
Alloy.Globals.LocalFunctions = {
setLogin : function setLogin(uId, uNome, uPlataforma){
var getLogin = Titanium.Network.createHTTPClient();
getLogin.open("POST","http://www.skrow.cc/ws-qia/controller.php");
var params = {
action: 'addLogin',
id: uId,
nome: uNome,
plataforma: uPlataforma
};
getLogin.send(params);
}
};
TiApp.xml
<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
<id>br.com.queroinvestiragora</id>
<name>Quero Investir Agora</name>
<version>1.0</version>
<publisher>silviosampaio</publisher>
<url>http://www.queroinvestiragora.com.br</url>
<description>undefined</description>
<copyright>2015 by silviosampaio</copyright>
<icon>appicon.png</icon>
<fullscreen>false</fullscreen>
<navbar-hidden>false</navbar-hidden>
<analytics>true</analytics>
<guid>284edc0c-c599-4cae-9444-721cd3d22937</guid>
<property name="ti.ui.defaultunit" type="string">dp</property>
<ios>
<plist>
<dict>
<key>UISupportedInterfaceOrientations~iphone</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIRequiresPersistentWiFi</key>
<false/>
<key>UIPrerenderedIcon</key>
<false/>
<key>UIStatusBarHidden</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.appcelerator.kitchensink</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kitchensink</string>
<string>936940282991759</string>
</array>
</dict>
</array>
</dict>
</plist>
</ios>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="#style/Theme.NoActionBar">
<activity android:label="#string/app_name"
android:name="com.facebook.LoginActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/>
</application>
</manifest>
</android>
<mobileweb>
<precache/>
<splash>
<enabled>true</enabled>
<inline-css-images>true</inline-css-images>
</splash>
<theme>default</theme>
</mobileweb>
<modules>
<module platform="commonjs">ti.cloud</module>
<module platform="android" version="3.0.3">facebook</module>
<module platform="iphone" version="3.2.0">facebook</module>
</modules>
<deployment-targets>
<target device="android">true</target>
<target device="blackberry">false</target>
<target device="ipad">false</target>
<target device="iphone">true</target>
<target device="mobileweb">false</target>
</deployment-targets>
<sdk-version>3.5.1.GA</sdk-version>
<plugins>
<plugin version="1.0">ti.alloy</plugin>
</plugins>
<property name="appc-app-id" type="string">55ec85b523ec2d9730087189</property>
<property name="acs-authbase-url-development" type="string">https://secure-identity.cloud.appcelerator.com</property>
<property name="acs-base-url-development" type="string">https://api.cloud.appcelerator.com</property>
<property name="acs-oauth-secret-development" type="string">0VlBf7xO3Z3aWr2ISM6BXr2vxQH8OPaU</property>
<property name="acs-oauth-key-development" type="string">T8j8E5AOcEyUGOPtSZWaA4ygJLpi0pYL</property>
<property name="acs-api-key-development" type="string">5p3UAhCmk7I3H9lYzip5Wb97H0h9I38V</property>
<property name="acs-username-development" type="string">appc_app_user_dev</property>
<property name="acs-password-development" type="string">fUoxkjYTGqxoE8ZTJ0</property>
<property name="acs-authbase-url-production" type="string">https://secure-identity.cloud.appcelerator.com</property>
<property name="acs-base-url-production" type="string">https://api.cloud.appcelerator.com</property>
<property name="acs-oauth-secret-production" type="string">2JHJ4oZ4V0Ch5Gvy3GAnEkY4stnycUYn</property>
<property name="acs-oauth-key-production" type="string">UTUK7lzz2Vuq54fSAErTk4NaN3kghPOJ</property>
<property name="acs-api-key-production" type="string">3xGYGFJQAYXBK4quHslbKCfBtgAcCgXg</property>
<property name="acs-username-production" type="string">appc_app_user</property>
<property name="acs-password-production" type="string">rDD4YG0qQxtmdXg0yM</property>
<property name="appc-org-id" type="string">100026191</property>
<property name="appc-creator-user-id" type="string">baea2ab2-d377-4f02-aa1b-6b4553ffe12d</property>
</ti:app>
alloy.js is always executed when your app starts but variables you create inside it are not accessible from other controllers by default.
You will need to make your facebook module accessible in the global scope to access it outside alloy.js, you can do this by changing the following lines in alloy.js:
var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();
To:
Alloy.Globals.fb = require('facebook');
Alloy.Globals.fb.permissions = ['public_profile', 'read_stream'];
Alloy.Globals.fb.appid = 172237596444060;
Alloy.Globals.fb.forceDialogAuth = false;
In login.js you also need to set the callback function for a successful facebook login before calling fb.initialize() Eg:
Alloy.Globals.fb.addEventListener('login', fbLogin);
Also you must set your login/logout functions before you try to call fb.initialize() or fb.authorize() so you will need to move fb.initialize() to login.js or just remove it from alloy.js since you are already calling fb.authorize().
I've just updated XCode to the 7.0 (7A220) and this take my Simulators to iOS9.
From that moment I cannot perform successfully any OAUTH call from the simulators.. I tried every model, from my App to the "sample Xamarin.Auth App".
The answer is always the same:
"Authentication Error
An SSL error has occurred and a secure connection to the server cannot be made"
The Code is the STANDARD one, I only changed my AppID.
The same code is working on the Android version of the same App!
var auth = new OAuth2Authenticator (
clientId: "my app id",
scope: "",
authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));
auth.AllowCancel = allowCancel;
// If authorization succeeds or is canceled, .Completed will be fired.
auth.Completed += (s, e) =>
{
// We presented the UI, so it's up to us to dismiss it.
dialog.DismissViewController (true, null);
if (!e.IsAuthenticated) {
facebookStatus.Caption = "Not authorized";
dialog.ReloadData();
return;
}
// Now that we're logged in, make a OAuth2 request to get the user's info.
var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
request.GetResponseAsync().ContinueWith (t => {
if (t.IsFaulted)
facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
else if (t.IsCanceled)
facebookStatus.Caption = "Canceled";
else
{
var obj = JsonValue.Parse (t.Result.GetResponseText());
facebookStatus.Caption = "Logged in as " + obj["name"];
}
dialog.ReloadData();
}, uiScheduler);
};
UIViewController vc = auth.GetUI ();
dialog.PresentViewController (vc, true, null);
The IOS9 Simulator can surf the web, so it is not a "connectivity problem". I also tried with Facebook SDK, same error. Could it be a certificate issue?
Thanks
To Fix this problem, simply add to your Info.plist file these lines:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
If you don't care about extra rules for domains, you can simply add:
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
NOTE: you have to Clean and Rebuild the project in order to see it running with these new settings!