I have a problem with custom URL schema. I think I've configured it properly but it doesn't open the app if it is closed, if the app is in "background" (i.e. I can see it double tapping the home button) the app is opened when I tap on the link.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.test</string>
<key>CFBundleURLSchemes</key>
<array>
<string>test</string>
<string>test1</string>
</array>
</dict>
</array>
the link is
TEST
other applications work fine but not mine.
Thanks,
Matteo
Do you return NO; anywhere in your - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation method?
I can't think of anything that would cause it to not open, aside from returning NO.
Related
I have seen this application on iTunes, it is creating custom icon in iphone. In my application I also want to change icon , specifically what I want to do is in my icon there is one label and programmatically I want to change the value of label.
From the video tutorial of the app, it seems like all they're doing is they created a web page with favicon of the custom icon that you created, then the user would tap "Add To Home Screen" to add the custom web page to the home screen. That should be enough to get you going.
It is possible to change appIcon from iOS 10.3.
Swift 3:
if UIApplication.shared.supportsAlternateIcons{
UIApplication.shared.setAlternateIconName("icon2", completionHandler: { (error) in
print(error ?? "")
})
}
Objective C:
[[UIApplication sharedApplication] setAlternateIconName:#"icon2" completionHandler:^(NSError * _Nullable error) {
//NSLog(#"Error...");
}];
set supportsAlternateIcon to Yes in info.plist. Both primary and secondary icons should be added in CFBundleIcons key of your app's Info.plist file.
//Info.plist
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>Icon1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon1</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>Icon2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon2</string>
</array>
</dict>
</dict>
</dict>
References:
Apple Document: setAlternateIconName(_:completionHandler:)
How to change your app icon dynamically with setAlternateIconName()
This is not possible. Unless your app is of Newsstand category. For newsstand app, change the icon using the code,
UIApplication *app = [UIApplication sharedApplication];
[app setNewsstandIconImage:newsstandImage];
Note: What #Enrico suggests is a different solution. Your app icon will still be there in home screen, a duplicate icon will be created. Which most of the users wont prefer.
Only my two cents.
Adding to plist directly is fine, the net effect is to have a "strange" value (IOS5...) in plist if seen visually in Xcode:
2) on simulator (Xcode 10 beta...) debug console on run you will see:
MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
but works
3) don't call directly in AppDelegate. if needed so, call it dispatched:
final func changeIcon(){
let name = "Icon1"
let icon = UIImage(named: name)
if UIApplication.shared.supportsAlternateIcons{
UIApplication.shared.setAlternateIconName(name, completionHandler: { (error) in
print(error ?? "ok")
})
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let when = DispatchTime.now() + 1
DispatchQueue.main.asyncAfter(deadline: when) {
self.changeIcon()
}
return true
}
.....
4) note: icon name is the symbolic name you put in key in upper level, so for example:
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>Icon1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>logo2_120x120</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>Icon2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>logo3_120x120</string>
</array>
</dict>
</dict>
</dict>
and do NOT add #2x or similar in plist.
I am trying to launch my app with a custom URL scheme. If the app is backgrounded, all is fine. If the app is not backgrounded, it launches, and the launch screen never disappears, eventually it gets killed by iOS for taking too long. I have extensively debugged this, and cannot figure out the problem. I have even removed everything from my application didFinishLauinchingWithOptions to make sure that nothing was stopping it there. This is my altered code, all I am asking is that it opens and gives me a blank window, but won't even do that. Just hangs on launch screen.
if ([launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]) {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[UIViewController alloc]init];
return YES;
}
URL Scheme in 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">
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb23423444322</string>
<string>test</string>
</array>
</dict>
</array>
</plist>
How are you handling what happens when your application responds to the URL Scheme. You should be use this delegate method in your App Delegate:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Do what you need here
return YES;
}
Check the contents of didFinishLaunchingWithOptions. The code in this method should not be commented out. Also it looks like you have a conditional in the didFinishLaunchingWithOptions method. This is most likely while the app is hanging on startup.
I am trying to open my native iPhone application from a link in safari. I have followed this link to create a url schema. I have added appgo:// as my url schema and com.xxxx.appgo as Identifier under URL Types. Following is my link in web page in safari: Open iPhone App
But when I click on the link the app doesn't open up and safari produce an alert with error: Safari cannot enter the page as the address is invalid.
my bundle identifier: com.xxxxx.abc
Note: My bundle identifier is different from the identifier in URL types. Can that be an issue?
Edit:
I have made bundle identifier and url identifier same. I have also added following code in my app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
NSLog(#"application");
BOOL returnValue = NO;
NSString *urlString = [url absoluteString];
if([urlString hasPrefix:#"com.xxxx.appgo"]){
returnValue = YES;
}
return returnValue;
}
I am testing it in my iPad. I first install the latest version of app from xcode and then press on home button and then open the link in safari. But I am still getting the alert saying the Safari cannot enter the page as address is invalid. My link in safari:
Open iPhone App
Implement in app delegate
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
BOOL returnValue = NO;
NSString *urlString = [url absoluteString];
if([urlString hasPrefix:#"appgo://"]){
returnValue = YES;
}
return returnValue;
}
Edit:
Add in your info.plist file
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.xxxx.appgo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>appgo</string>
<string>yourSecondScheme</string>
</array>
</dict>
</array>
Yes. Your bundle identifier must be same as the URL types in the plis file.
For more you can refer to this link.
I need to send file from one application to another. I use UIDocumentInteractionController to copy file.
Here is my code implementing UIDocumentInterationController in my ViewController in SendingApp.
NSString *path = [[NSBundle mainBundle] pathForResource:#"1" ofType:#"zip"];
NSURL *urlPath = [NSURL fileURLWithPath:path];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:urlPath];
[docController retain];
docController.delegate = self;
[docController presentOpenInMenuFromRect:self.view.frame
inView:self.view
animated:YES];
docController is property. ViewController implements UIDocumentInteractionControllerDelegate.
The ReceiverApp is set to handle the files of this extension.
My ReceiverAppInfo.plist
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>zip</string>
</array>
<key>CFBundleTypeName</key>
<string>ZIP</string>
<key>LSItemContentTypes</key>
<array>
<string>public.zip-archive</string>
<string>com.pkware.zip-archive</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
In ReceiverAppDelegate I use
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to handle opening of receiving file.
So problem is that this code works just perfect on iOS 5.1 BUT it doesn't work on iOS 6. UIDocumentInteractionController OpenIn menu appears and shows my ReceiverApp but it doesn't do anything if you select the app. I looked in Console and found out that iPhone Simulator 6.1 tries to copy file to one directory while Simulator 5.1 copies to another.
iPhoneSimulator 6.1
com.apple.mdt[2342]:
Copy ~/Library/Application Support/iPhone Simulator/6.1/Applications/367D395F-DC8B-4F4C-83C7-B22992E34C64/sendingZIP.app/1.zip ->
/var/mobile/Library/Application Support/Containers/-23.ReceiveApp/Documents/Inbox
iPhoneSimulator 5.1
com.apple.mdt[2439]:
Copy ~/Library/Application Support/iPhone Simulator/5.1/Applications/0DE1852A-F803-4583-87BC-8F1EBBE362A4/sendingZIP.app/1.zip ->
~/Library/Application Support/iPhone Simulator/5.1/Applications/927E310A-2766-4709-81CB-0E759F24236D/Documents/Inbox
Has anybody such problem? Does anybody know what to do?
Notice that the only discernible API difference is
Managing Actions
– documentInteractionController:canPerformAction: Deprecated in iOS 6.0
– documentInteractionController:performAction: Deprecated in iOS 6.0
Are you still implementing these methods? Maybe they are responsible for the unexpected results.
I'm just getting into iOS development, but something I'm going to have to do early on is add a button to the system menus like how Dropbox has added its button when interacting with email attachments.
This application will be for video so adding a button on the share menu for quicktime players would be ideal.
I've scoured the documentation and have only found the UIMenuItem class. Is this what I want or is there another way to implement this functionality?
Set project-info.plist -> add new item (UTExportedTypeDeclarations)
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.apple.quicktime-movie</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.company.project</string>
<key>UTTypeTagSpecification</key>
<dict/>
</dict>
</array>
Coding your ButtonClick event in .m file
-(IBAction)actionClick:(id)sender{
UIDocumentInteractionController *documentController =
[UIDocumentInteractionController interactionControllerWithURL:
[NSURL fileURLWithPath:MOVIE_FILE_PATH]];
documentController.delegate = self;
documentController.UTI = #"com.apple.quicktime-movie";
[documentController presentOpenInMenuFromRect:CGRectZero
inView:self.view
animated:YES];
}