canOpenURL: failed for URL: "instagram://app" - error: "(null) - swift

I get this error:
-canOpenURL: failed for URL: "instagram://app" - error: "(null)"
This is the code I use:
let instagramURL = NSURL(string: "instagram://app")!
if (UIApplication.sharedApplication().canOpenURL(instagramURL)) {
//some code
}
I added LSApplicationQueriesSchemes to my info.plist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
And it seems to "recognise" the instagram scheme, cause when I use something else like "instagraam" I get a different error message (which makes sense):
-canOpenURL: failed for URL: "instagraam://app" - error: "This app is not allowed to query for scheme instagraam"
Am I missing something obvious?

As pointed out in the comments - this is in fact a duplicate of this.
On a real device it works, it's just weird output of the simulator.

Related

Issues loading Images Xcode Swift 5 (SDWebImage/Backblaze used)

i am encountering a weird issue.
Short version
We have an app in the appstore for multiple months now with a photo feed. We have plenty of users (99,9% in Europe, mostly Central Europe).
using SDwebImage for image downloading
Backblaze as cloud storage
The issue:
On our end there is no issue. And none of our users encounter issues when showing the images.
However when Apple reviews our app, they are not able to download images at all (the exact same which work for us and all users).
What we tested
SDWebImage was shortly replaced with Kingfisher -> same result
We tried to reproduce the issue but weren't able: We set the location of our simulator to all possible locations + changed languages, clean rebuild etc. Never encountered the issue.
We tried around with AllowArbitrary loads but still won't work for our Apple reviewer.
Code
postImageView.sd_imageIndicator?.startAnimatingIndicator()
let photoUrl = URL(string: photoUrlString)
postImageView.backgroundColor = .systemGray3
postImageView.sd_imageIndicator = SDWebImageActivityIndicator.grayLarge
SDWebImageDownloader.shared.config.downloadTimeout = 40
postImageView.sd_setImage(with: photoUrl, placeholderImage: nil, options: .allowInvalidSSLCertificates) { (image, err, sd, url) in
self.postImageView.sd_imageIndicator = nil
self.postImageView.sd_imageIndicator?.stopAnimatingIndicator()
if err != nil {
self.postImageView.image = UIImage(named: "placeholder-image")
Ref().databaseProblems.child("IMAGE_IOS").child(UUID().uuidString).setValue("\(err.debugDescription) + \(err?.localizedDescription ?? "")")
}
}
the error codes
Optional(Error Domain=NSURLErrorDomain Code=-1001 \"The request timed out.\" UserInfo={_kCFStreamErrorCodeKey=60, NSUnderlyingError=0x28334f120 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 \"(null)\" UserInfo={_kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <49574986-C917-4980-ABC7-6A9E9EBD6892>.<3>, _NSURLErrorRelatedURLSessionTaskErrorKey=(\n \"LocalDataTask <49574986-C917-4980-ABC7-6A9E9EBD6892>.<3>\"\n), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://f000.backblazeb2.com/file/Images/-MVVvWz3rlPQw5J5_Ah_, NSErrorFailingURLKey=https://f000.backblazeb2.com/file/Images/-MVVvWz3rlPQw5J5_Ah_, _kCFStreamErrorDomainKey=1}) + The request timed out."
"Optional(Error Domain=SDWebImageErrorDomain Code=2002 \"Operation cancelled by user during sending the request\" UserInfo={NSLocalizedDescription=Operation cancelled by user during sending the request}) + Operation cancelled by user during sending the request"
"Optional(Error Domain=NSURLErrorDomain Code=-1022 \"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.\" UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLStringKey=http://f000.backblazeb2.com/file/Images/-MVTKiJrFDOldW94d0cO, NSErrorFailingURLKey=http://f000.backblazeb2.com/file/Images/-MVTKiJrFDOldW94d0cO, _NSURLErrorRelatedURLSessionTaskErrorKey=(\n \"LocalDataTask <F3ADD147-226D-48EF-8B3A-2C61EF2887FE>.<2>\"\n), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <F3ADD147-226D-48EF-8B3A-2C61EF2887FE>.<2>, NSUnderlyingError=0x60400036d550 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 \"(null)\"}}) + The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."
info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>https://f000.backblazeb2.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Any idea/suggestion?

Apple Music API not letting me get User Token - Throwing Unknown Error

I am trying to create a very simple app using Apple's Apple Music API in Swift. To do this, I need to retrieve songs from Apple Music. I am trying to get a user token using this code
SKCloudServiceController().requestUserToken(forDeveloperToken: "[DEV TOKEN HERE]") { (userToken, err) in
if let e = err {
print(e)
}
if let token = userToken {
print(token)
}
}
Right now I am just trying to print the token, but every time I call this function I am met with this error in console
Error Domain=SKErrorDomain Code=0 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred}
I am confident that it is not my Dev Token because that usually throws a 'Cannot Connect to iTunes' error and I have tried substituting random strings for my dev token just to get the same error.
I've looked around but I cannot find an answer to this, has anyone else encountered it or have any idea how to fix it?
Thank you!
P.S I am not too familiar with posting on Stack Overflow so if I made some mistake please let me know so I can correct it!
Same here. It worked before 14.2. Developer Token is valid, I checked Dev Center.

Apple Script fails when run from within a macOS Swift-based application

SOLUTION:
I needed to do two things to solve my problem:
1) Add the following to my app's entitlements file:
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.Mail</string>
</array>
2) Add the following to my app's plist:
<key>NSAppleEventsUsageDescription</key>
<string>Please allow "your message here"</string>
This works on Mojave 10.14 (18A389)
I have a basic Swift-based macOS app. I'd like to use Apple Script to determine the number of unread email messages in Mail.app. I created a small Apple Script and tested it in Script Debugger (it works fine).
When I run the same script from within my app though it fails stating that the Mail application isn't running (even though it is):
let unreadEmailsScript = """
tell application "Mail"
get unread count of inbox
end tell
"""
if let scriptObject = NSAppleScript(source: unreadEmailsScript) {
var errorDict: NSDictionary? = nil
scriptObject.executeAndReturnError(&errorDict)
if let error = errorDict {
print(error)
}
}
Output:
{
NSAppleScriptErrorAppName = Mail;
NSAppleScriptErrorBriefMessage = "Application isn't running.";
NSAppleScriptErrorMessage = "Mail got an error: Application isn't running.";
NSAppleScriptErrorNumber = "-600";
NSAppleScriptErrorRange = "NSRange: {33, 12}";
}
I haven't executed Apple Script from within an app before. Is this error due to a permissions problem?
Yes, it's a permission problem.
Your app is sandboxed and you have to specify appropriate entitlements. Add this in the entitlements file of your app:
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.Mail</string>
</array>

Facebook Account Kit SDK gives invalid OAuth 2.0 error

I have integrated Account kit sdk in to my project.
I created the application on facebook development dashboard, enabled Account Kit on it. Got app-id and client access token.
I added it into info.plist file. I am getting this error:
[AccountKit][Error]: Invalid OAuth 2.0 Access Token
2016-05-31 02:41:32.191 Chat[2919:563260] [AccountKit][Error]:
Persisting App Events due to error:
Error Domain=com.facebook.accountkit:Error Code=200 "(null)"
UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token., NSUnderlyingError=0x147596a30
{Error Domain=com.facebook.accountkit:ServerError Code=190 "(null)" UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token.}}}
Please need help. Thanks
Make sure you have the correct settings in info.plist.
I had a similar problem and in my case it was missing a key FacebookAppID
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>AccountKitClientToken</key>
<string>{your-account-kit-client-token}</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>ak{your-app-id}</string>
</array>
</dict>
</array>
Make sure that initialization response type of AKFAccountKit matches with your application dashboard configuration.
It can be:
accountKit = [[AKFAccountKit alloc] initWithResponseType:AKFResponseTypeAccessToken];
or
accountKit = [[AKFAccountKit alloc]initWithResponseType:AKFResponseTypeAuthorizationCode];
This might be an issue with your configuration. You can file a bug report with Facebook here including your token information: https://developers.facebook.com/bugs/
I got this error when I had copied the wrong AccountKitClientToken into the Info.plist. Got the right one in there and everything is working now!
You can add your client token using AKFSettings.setClientToken("MY TOKEN") and make sure to import AccountKit at the top of the file where you call this.

Facebook image upload on a page working properly in simulator but not in device

When I run same code in simulator I get success Response for image post:
{
id = 248572435289479;
"post_id" = "244759709004085_248572441956145";
}
When I run in same code in device I get:
Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x208a8dd0 {error={
code = 1;
message = "(#1) An unknown error occurred";
type = OAuthException;
}}
"
OAuthException means that there was an authentication issue. Be sure that the following are true on your device.
You are logged into a facebook account successfully
If you are, then remove the app from the phone
Do a clean and re-deploy to the phone
If none of the above work, try logging out in Settings on the phone and logging back in. Then try logging in through safari. Sometimes the iOS facebook authentication can be a little buggy. Also try a different app that is guaranteed to work with iOS facebook accounts. Something like, Hootsuite.
If there is still an issue after all that... I am not sure what you tell you.
This link might help you.
and #giff's answer also explains it to some extent on this link.
log of your issue in this might help you to get further detail of your error.
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSLog(#"%#", [error localizedDescription]);
NSLog(#"Err details: %#", [error description]);
};
I recommend you to try this if none of the solutions given above could help you.
Remove the application from the list of authorized applications and authorize it again with the needed permissions.
Hope this works for you