Monday, May 22, 2017

iOS application icon change without appstore update on iOS 10.3

In other words, an update is no longer required to push out the new icon artwork.
The seemingly unimportant change opens up a world of new possibilities for interactions with your favorite apps that simply were not possible before.
Taking advantage of the iOS 10.3 SDK, developers can now use a new Instance method to specify the primary app icon as well as one or more alternate icons.
iOS developer Steve Stroughton-Smith explained that apps must ask your permission before changing their icon. Granting permission yields an alert like the one you see below, informing you of an icon change.

So let see, how to change the icon in your app.

If you see in your Info.plist file, Icon files new entity, showing a way you need to put all icon information in plist.




In order to Icon change process, should include here

    switch (sender.selectedSegmentIndex) {
        case 0:
            [[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
        case 1:
            [[UIApplication sharedApplication] setAlternateIconName:@"Test1" completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
        case 2:
            [[UIApplication sharedApplication] setAlternateIconName:@"Test2" completionHandler:^(NSError * _Nullable error) {
                NSLog(@"error = %@", error.localizedDescription);
            }];
            break;
           
        default:
            break;
    }
Demo Code

Tuesday, January 17, 2017

Swift some important note.

Who are swift struggling to comment, pragma, .warning, to do or other imports note to write, which one to next time or fix some issue, it's embarrassing to who already working on Objective-C, here we go with some swift important slip.

Comment:

Single line: //
Multi Line: /* here your commommnets*/

Pragma or methods section mark which Objective-C is called #pragma

//MARK:UITableViewDelegate

Warning:

//TODO: this method complete next day 

Logical change or need to fix somethings then:

//FIXME: logical error here, or should update depreciated

Thursday, January 5, 2017

Access resource from main bundle using Swift 3.0


Plist read from the main bundle:

let plistPath = Bundle.main.path(forResource: "plist name", ofType: "plist")
let dataList = :NSArray = NSArray(contentsOfFile: plistPath!)!
print(dataList)

Info Plist access:

let appDisplayName:String = Bundle.main.infoDictionary!["CFBundleDisplayName"] as! String


Monday, November 21, 2016

Dynamic CollectionView Cell size create based on text length size .



Firstly we need to calculate text length and configure to collection view cell size layout.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
        CGSize calCulateSize =[(NSString*)[_categoryList objectAtIndex:indexPath.row] sizeWithAttributes:NULL];
        calCulateSize.width = calCulateSize.width+50; // for better look we add more 50 pixel
        calCulateSize.height = 50; // fixed height
        return calCulateSize;
}



as usual, we implement all of the required collection view delegate and data source, then we see look like collection view cell. demo attached here, if any things need, let me know.


Demo here

Wednesday, November 2, 2016

iOS extension to Host app data share.

Most of the developer struggle data send the extension to Host app, We try to figure out this issue.

Steps:

1. Create  new project ->Xcode->File->New->Project->Single View Application
2. Extension Target add -> File->New->Target->iMessage Extension (also you choose your one)

Host App

1. Info.plist add URL scheme
       <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>url.Identifier</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.avigitsaha.halloweenwallpaperhd.Schemes</string>
            </array>
        </dict>
    </array>

2. AppDelegate.m

 - (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
   
    NSLog(@"options %@",options);
    NSLog(@"URL scheme:%@", [url scheme]);
    NSLog(@"URL query:1234 %@", [url query]);
   
    NSURLComponents *urlComponents;
    NSArray* queryItems;
   
    // init
    urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
    queryItems = [urlComponents queryItems];
   
    for (NSURLQueryItem* item in queryItems)
    {
        if ([[item name] isEqualToString:@"imageId"]){
            NSLog(@"image Id %@",[item value]);
        }
       
        if ([[item name] isEqualToString:@"categoryId"]){
            NSLog(@"Category Id %@",[item value]);
        }
       
    }
    return NO;
}

Extension App

1. UIButton added for host app code here

- (IBAction)openHostAppWithData:(UIButton *)sender {
    NSString *customURL = [NSString stringWithFormat:@"com.avigitsaha.halloweenwallpaperhd.Schemes://"];
   
    NSURLComponents* urlComponents;
    urlComponents = [NSURLComponents componentsWithURL:[NSURL URLWithString:customURL] resolvingAgainstBaseURL:NO];
   
    [urlComponents setQueryItems:@[[NSURLQueryItem queryItemWithName:@"imageId" value:@"1"],[NSURLQueryItem queryItemWithName:@"categoryId" value:@"2"]
                                   ]];
    [self.extensionContext openURL:[urlComponents URL] completionHandler:^(BOOL success){
        NSLog(@"success %d",success);
    }];
}

Here attached Demo project

Thursday, October 13, 2016

How do I prevent files from being backed up to iCloud and iTunes from my iOS app using Swift or ObjectiveC



Objective C:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
   
    NSError *error = nil;
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

Swift 3.0:

    func addSkipBackupAttributeToItemAtURL(filePath:String) -> Bool
       
    {
       let URL:NSURL = NSURL.fileURL(withPath: filePath) as NSURL
        assert(FileManager.default.fileExists(atPath: filePath), "File \(filePath) does not exist")
        var success: Bool
       
        do {
            try URL.setResourceValue(true, forKey:URLResourceKey.isExcludedFromBackupKey)
            success = true
        } catch let error as NSError {
           success = false
          print("Error excluding \(URL.lastPathComponent) from backup \(error)");
       }
        return success
    }

Sunday, October 9, 2016

Xcode 8 iOS Simulator Activity Logging Tracing


Xcode 8 iOS application run on simulator we see lots of debugging messages, which are call Activity tracing.
Now we are learning, how to Activity logging tracing enable and disable:


Editor Scheme
















argument setting















Now are add environment add (+):
name:OS_ACTIVITY_MODE
value:disable
activity mode set










Now have a look your simulator debugging section, system logging is not showing, If want to deactivate this feature just uncheck, not to remove OS_ACTIVITY_MODE.