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