canOpenURL failing for system-wide URL schemes

后端 未结 7 1931
-上瘾入骨i
-上瘾入骨i 2020-12-16 10:18

I\'m running iOS 9b5.

In my app, if a device can make a phone call, I want to color the text blue so it looks tappable. If not, I leave it black.

In order to

7条回答
  •  离开以前
    2020-12-16 11:02

    As iOS9 deprecates stringByAddingPercentEscapesUsingEncoding, the following can be used to clean the telprompt: URL.

    NSString *cleanedString = [[[PHONE NUMBER] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
    //NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", escapedPhoneNumber];
    NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
    
    if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
        [[UIApplication sharedApplication] openURL:phoneURL];
    }
    

提交回复
热议问题